I would like to use options in the static method QFileDialog.getOpenFileName.
For example i would like to set two options: QFileDialog.ExistingFile and QFileDialog.Detail.
I have already read this text: http://pyside.github.io/docs/pyside/PySide/QtGui/QFileDialog.html?highlight=getopenfilename#PySide.QtGui.PySide.QtGui.QFileDialog.getOpenFileName but i don't understand how i can use PySide.QtGui.QFileDialog.Options?
dir = self.sourceDir
filters = "Text files (*.txt);;Images (*.png *.xpm *.jpg)"
selected_filter = "Images (*.png *.xpm *.jpg)"
options = "" # ???
fileObj = QFileDialog.getOpenFileName(self, " File dialog ", dir, filters, selected_filter, options)
If i use
options = QFileDialog.DirectoryOnly
options |= QFileDialog.List
it does not work.
(Windows 7 64 Bit, PyCharm 3.4.1 Pro, Python 3.4.0, PySide 1.2.2)
You cannot do this if you are using the static functions with a native file-dialog.
The native file-dialogs do not have the same API as the Qt file-dialog, so you can only set the properties that are available via the static function arguments - which means the caption, title, working-directory, filters, and options.
The static functions more or less match the various file modes:
AnyFile = getSaveFileName
ExistingFile = getOpenFileName
Directory = getExistingDirectory
ExistingFiles = getOpenFileNames
When using the static functions, the ShowDirsOnly
option will only work with getExistingDirectory
. But on Windows, that will open the native "Browse For Folder" dialog (unless you set the DontUseNativeDialog
option), and so the ShowDirsOnly
option would be redundant.
There is currently no way to set the ViewMode
for a native-dialog when using the static functions, and the same goes for all the other APIs that are specific to QFileDialog
.
Long-story short: if you want more control over the file-dialog, use the built-in Qt one - that's what it's there for.