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



  • 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


  • Lifetime Qt Champion

    Hi,

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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.