Unsolved PyQT5 QFileDialog only works correctly when the file mode is set to 'Directory'
-
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.
-
Well, if there are no existing files that match your filter then it would fail, right?