Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Choosing a directory using FileDialog
Forum Updated to NodeBB v4.3 + New Features

Choosing a directory using FileDialog

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 219 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Svenb
    wrote on last edited by Svenb
    #1

    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.04

    FileDialog {
           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");
           }
       }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by dheerendra
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved