Choosing a directory using FileDialog
-
Greetings,
Task:
Allow the user to select an output directory using FileDialog window. No files should be displayed only folders/directories.
Problem:
When using FileDialog in directory mode with the ShowDirsOnly option applied, I am unable to press the save button. I am able to navigate folders and directories without seeing files, however the save button remains greyed out.
Using FileDialog in directory mode without the ShowDirsOnly option selected, allows me to select a file (not a dir) and press save. The directory is then outputted to the outputDirLabel.text. Even though this works, this is not the functionality that I require as it is unintuitive to the user.
Any suggestions would be appreciated.
Code:
QT Version: 6.7.2
OS: Linux Ubuntu 22.04FileDialog { id: fileDialogOutput title: qsTr("Select Output Directory") fileMode: FileDialog.Directory options: { FileDialog.ShowDirsOnly } // nameFilters: ["Directories Only"] onAccepted: { if (fileDialogOutput.folder) { outputDirLabel.color = "green"; outputDirLabel.text = fileDialogOutput.folder; } } onRejected: { outputDirLabel.color = "red"; outputDirLabel.text = qsTr("No output directory selected"); } }
-
It is not giving the option to select the directory. "Save" button will not be enabled unless there some text exist in the "Save As:". As a work-around type the FolderName you want in the "Save As". Save button will be enable. Now if you click on the save button, directory you entered will be set to selectedFile property.
console.log(" File Selected.......folder.."+fileDialogOutput.selectedFile)
According to the documentation, there is no mention of directory selection. However 5.15.x FileDialog does mention the directory selection. I see FileDialog disparity between Qt 5.15.x to 6.x. I will file a enhancement bug for this.