Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Folder browser dialog in Qt

Is there any way to open a folder browser dialog in Qt? When I use QFileDialog with Directory file mode, even if I specify the ShowDirsOnly option, I get the standard file dialog. I would prefer to use a dialog that asks the user to choose a directory from a directory tree.

Here's the PySide code I'm using:

from PySide import QtGui
app = QtGui.QApplication([])
dialog = QtGui.QFileDialog()
dialog.setFileMode(QtGui.QFileDialog.Directory)
dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
dialog.exec_()

And here's the result I get on Windows 7: File selection dialog

like image 498
Vojislav Stojkovic Avatar asked Nov 08 '12 22:11

Vojislav Stojkovic


1 Answers

It appears that the order in which you call setFileMode() and setOption() matters. Make sure you're calling setFileMode() first:

QFileDialog dialog;
dialog.setFileMode(QFileDialog::Directory);
dialog.setOption(QFileDialog::ShowDirsOnly);
...
like image 75
Chris Avatar answered Oct 17 '22 22:10

Chris