Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileDialog: setFileMode(QFileDialog::Directory) not showing both directories and files and can I use one filedialog to choose both file and folder?
Forum Update on Monday, May 27th 2025

QFileDialog: setFileMode(QFileDialog::Directory) not showing both directories and files and can I use one filedialog to choose both file and folder?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.1k 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.
  • M Offline
    M Offline
    magurmach
    wrote on last edited by
    #1

    I need to provide an option to select both file and folder and when I need to choose a file, I can easily choose file browser.

    "Documentation":qt-project.org/doc/qt-4.8/qfiledialog.html says, with file mode QFileDialog::Directory both files and directories are displayed. But, it's not showing files. It is showing files when I choose to use options like
    DontUseNaticeDialog e.g. setOption(QFileDialog::DontUseNativeDialog, true);

    But I can't Native Dialog go, it looks very good. Now, how can I get a FileDialog that selects both file and folder.

    The demo code I have now:
    @
    QFileDialog x;
    x.setFileMode(QFileDialog::Directory);
    x.setWindowTitle("Select Folder or File(s)");
    x.setViewMode(QFileDialog::Detail);
    if(x.exec())
    {
    QStringList fileNames = x.selectedFiles();
    qDebug()<<fileNames<<endl;
    }
    @

    I am using Windows 7 64 bit and Qt 5.2.1

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK, It's not possible. The QFileDialog::Directory mode should show both, but you can only select a directory

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • O Offline
        O Offline
        ondrejandrej
        wrote on last edited by
        #3

        I'm trying to make a dialog where only directory can be selected, but where both files and directories are shown. I tried this:
        @ QFileDialog dialog;
        dialog.setFileMode(QFileDialog::Directory);
        dialog.setOption(QFileDialog::ShowDirsOnly, false);
        //dialog.setOption(QFileDialog::DontUseNativeDialog);
        if(!dialog.exec())
        return;@
        It shows just directories, unlike SGaist's post.

        However, when I uncomment the setOption(QFileDialog::DontUseNativeDialog), it works as expected and shows both. Only the dialog isn't so good-looking.

        This seems like a bug, doesn't it? Is there a workaround? I'm on Qt 5.3.1 on Windows.

        EDIT: I found this thread: http://stackoverflow.com/questions/19108339/qfiledialog-how-to-set-option-to-show-content-of-folder-in-getexistingdirector where they found the same on Qt 4.X. It's a pity that this still isn't fixed.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          ondrejandrej
          wrote on last edited by
          #4

          I'm trying to make a dialog where only directory can be selected, but where both files and directories are shown. I tried this:
          @ QFileDialog dialog;
          dialog.setFileMode(QFileDialog::Directory);
          dialog.setOption(QFileDialog::ShowDirsOnly, false);
          //dialog.setOption(QFileDialog::DontUseNativeDialog);
          if(!dialog.exec())
          return;@
          It shows just directories, unlike SGaist's post.

          However, when I uncomment the setOption(QFileDialog::DontUseNativeDialog), it works as expected and shows both. Only the dialog isn't so good-looking.

          This seems like a bug, doesn't it? Is there a workaround? I'm on Qt 5.3.1 on Windows.

          EDIT: I found this thread: http://stackoverflow.com/questions/19108339/qfiledialog-how-to-set-option-to-show-content-of-folder-in-getexistingdirector where they found the same on Qt 4.X. It's a pity that this still isn't fixed.

          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