(Windows 7 64 Bit, PyCharm 3.4.1 Pro, Python 3.4.0, PySide 1.2.2)
I want to make a file dialog with filters and preselect one filter.
If i use the static method, it works, i can use filters and preselect one filter.
dir = self.sourceDir
filters = "Text files (*.txt);;Images (*.png *.xpm *.jpg)"
selected_filter = "Images (*.png *.xpm *.jpg)"
fileObj = QFileDialog.getOpenFileName(self, " File dialog ", dir, filters, selected_filter)
If i use an object it does not work, my filters are not there.
file_dialog = QFileDialog(self)
file_dialog.setNameFilters("Text files (*.txt);;Images (*.png *.jpg)")
file_dialog.selectNameFilter("Images (*.png *.jpg)")
file_dialog.getOpenFileName()
Why does this not work?
Global solution is here. You can get directory, filename and file extension. You can use that:
and class is here!
You have misunderstood how
QFileDialog
works.The functions
getOpenFileName
,getSaveFileName
, etc are static. They create an internal file-dialog object, and the arguments to the function are used to set properties on it.But when you use the
QFileDialog
constructor, it creates an external instance, and so setting properties on it have no effect on the internal file-dialog object created by the static functions.What you have to do instead, is show the external instance you created: