[Solved] Qt5 - QFileDialog shows only directories

  • Hello,
    Since I use Qt5 (and not Qt4.8), my QFileDialog shows only directories and no files anymore.

    QString path;
    QFileDialog dialog(this);
    if (dialog.exec())
    path = dialog.selectedFiles().isEmpty() ? QString() : dialog.selectedFiles()[0];
    if (!path.isEmpty()){

    In addition, the QFileDialog doesn't use the stylesheet of its parent, but the native Windows-Style. It seems like Qt5 now uses the native "select directory"-dialog for the options above.
    But there is no change in the "documentation":https://qt-project.org/doc/qt-5.0/qtwidgets/qfiledialog.html#FileMode-enum, so how can I get that behaviour to be as it was in Qt4?
    I use Qt5.2.0-msvc2010-opengl on Win7.

    Thank you all :)

    [EDIT: Ok, I found the problem:
    Since Qt5, you need setOption(QFileDialog::DontUseNativeDialog) to disable the native dialog.
    I think it is a bit confusing that setFileMode(QFileDialog::Directory) doesn't show files on WIndows even if its mentioned to do it in the documentation, but well.]

  • Lifetime Qt Champion


    AFAIK, Qt 4 also used native dialogs by default.

    Then indeed, there's no styling propagated since the dialog comes directly from the OS (in your case windows) So are you saying the between Qt 4 and Qt 5 the native dialog doesn't do the same things ?

Log in to reply

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