[PyQt] Bug in QFileDialog for PyQt5 / Qt5.7 ?

Baz Walter bazwal at ftml.net
Thu Dec 1 18:19:12 GMT 2016

On 01/12/16 12:26, Massimo Vassalli wrote:
> Dear all,
> I found a strange behaviour (a bug ?) In the new implementation
> of QFileDialog I'm using with Qt5.7 / PyQt5.7.
> In short, the static function QFileDialog.getOpenFileNames() which is
> expected to let the user selet more than one file and return a list, does
> only half of the job. The dialog is executed with FileMode set to
> QFileDialog.ExistingFiles (so that the user can select more than one file)
> but the function returns only the first file of the list (the first clicked
> file, to be precise). A workaround is to instantiate the class QFileDialog
> and use it:
> q = QtWidgets.QFileDialog()
> q.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen)
> q.setFileMode(QtWidgets.QFileDialog.ExistingFiles)
> fnames = q.selectedFiles()
> Should it be considered a bug or was I wrong in using the static function ?

Works okay for me:

 >>> from PyQt5 import QtWidgets
 >>> app = QtWidgets.QApplication([''])
 >>> QtWidgets.QFileDialog.getOpenFileNames()
(['/usr/lib/python3.5/re.py', '/usr/lib/python3.5/os.py', 
'/usr/lib/python3.5/io.py'], 'All Files (*)')

More information about the PyQt mailing list