Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
PyQT5 QFileDialog only works correctly when the file mode is set to 'Directory'
randizzleDee last edited by
The following code works as expected:
dialog = QFileDialog(self) dialog.setFileMode(QFileDialog.Directory) if dialog.exec(): save_folder = dialog.selectedFiles()
However, changing the file mode and adding a filter causes the exec call to fail:
image_dialog = QFileDialog(self) image_dialog.setFileMode(QFileDialog.ExistingFiles) image_dialog.setNameFilter("Images (*.png *.jpg *.pgm)") if image_dialog.exec(): filename = image_dialog.selectedFiles()
Any Idea why this might be the case? Both code snippets reside in the same slot function within the main window class, and this behavior seems to be consistent no matter where In the program I move them to.
Denni 0 Banned last edited by Denni 0
Well sadly it does not work because if I copy that and paste it into a file it errors out because it is not a Minimal Reproducible Example -- so it will not work the same as whatever you are running -- so help yourself by helping us by including a MRE
Kent-Dorfman last edited by
Well, if there are no existing files that match your filter then it would fail, right?