Pyqt Qfiledialog Exec_ Is Slow
Solution 1:
The QFileDialog
constructor creates a Qt dialog, whereas the static functions (like getSaveFileName
) will create a native one (unless the DontUseNativeDialog option is set to True
).
The native dialogs may be faster or slower than Qt's, depending on the platform in use.
For some plaforms, though, it appears the problem may be more acute. See this longstanding bug, which affects Windows XP and Windows 7 (amongst others) with Qt 4.7 / 4.8.
UPDATE
Just to be clear:
On Windows, the static function QFileDialog.getExistingDirectory opens the native "Browse For Folder" dialog, which only allows selecting a single directory. So Qt cannot provide a native dialog for selecting multiple directories, because Windows doesn't provide one.
The other main alternative is to use Qt's own, non-native file-dialog and monkey-patch it as suggested in this faq. However, as you've already discovered, this currently has the significant downside of being annoyingly slow due to bugs in the underlying implementation.
The only remaining alternatives are to either write your own directory-lister dialog, or try to think of another way of solving your immediate problem (i.e. without using a file-dialog).
Solution 2:
I had very very slow performance from the default Qt file browser dialog. Listing a directory took ~5s and selecting a file took ~3s. Adding the "DontUseNativeDialog" option fixed my problem completely.
file_path = QtGui.QFileDialog.getSaveFileName( self, 'Title', path, "", "", QtGui.QFileDialog.DontUseNativeDialog )
print file_path
Post a Comment for "Pyqt Qfiledialog Exec_ Is Slow"