Jacob Frey
Jacob Frey

Reputation: 3

QFileDialog View Files and Folders when choosing a Directory

I'm new to learning the Qt library, and I'm having a hard time getting QFileDialog to work properly. I want the user to be able to select a directory but also be able to view the files and folders so they know which directory they should pick. I have seen things similar to this being posted elsewhere but everything I've tried hasn't made any difference in the output.

I've tried creating my own dialog and setting the mode to directory, which says that it should display both files and folders:

    QFileDialog myDialog(this);
    myFileExplorer.setFileMode(QFileDialog::Directory);
    myFileExplorer.setDirectory("C:/");
    QString file = myFileExplorer.exec();

And I've tried using getExistingDirectory as well, but with that function it always only shows the directory as well. Thanks

Upvotes: 0

Views: 3195

Answers (1)

Mikołaj Mularczyk
Mikołaj Mularczyk

Reputation: 969

QString getExistingDirectory ( QWidget * parent = 0, const QString & caption = QString(),
const QString & dir = QString(), Options options = ShowDirsOnly )

The default options parameter is set to show dirs only, you have to change it to

QFileDialog::DontUseNativeDialog

But unfortunately you won't be able to use native dialog.

Upvotes: 2

Related Questions