https://bugzilla.redhat.com/show_bug.cgi?id=2258467
Bug ID: 2258467 Summary: PyQt6 and PyQt5 ignore "dir" argument in QFileDialog.getOpenFileName Product: Fedora Version: 38 Hardware: x86_64 OS: Linux Status: NEW Component: python-pyqt6 Severity: medium Assignee: thunderbirdtr@fedoraproject.org Reporter: Michael.Clerx@gmail.com CC: epel-packagers-sig@lists.fedoraproject.org, jonathan@almalinux.org, kde-sig@lists.fedoraproject.org, manisandro@gmail.com, thunderbirdtr@fedoraproject.org Target Milestone: --- Classification: Fedora
Since some time in 2021 (https://bugreports.qt.io/browse/QTBUG-92961, https://stackoverflow.com/questions/75878424) I've been running into an issue where QFileDialog.getOpenFileName ignores the "dir" argument (recently renamed "directory"):
QtWidgets.QFileDialog.getOpenFileName( self, 'Open file', '/home/michael/some/path', )
This is supposed to create an open file dialog initialised at "/home/michael/some/path", but at some point (around Fedora 33?) this stopped working.
The same functionality for getSaveFileName() works as expected.
I've only just noticed that the bug disappears if I install PyQt5 or PyQt6 into a virtual environment using pip, even when I specify the exact same versions that DNF installs. So it looks like this is an issue with the packaged version only. Because it's been present for quite a while now, I can't pinpoint where it was introduced, but I have seen the same bug on multiple devices, and in fresh installs of a variety of versions.
A script to reproduce:
#!/usr/bin/env python3 import sys from PyQt6 import QtWidgets #from PyQt5 import QtWidgets
# Change this to a valid & accessible path (other than your home) path = '/home/michael/a/path/that/definitely/exists'
class App(QtWidgets.QMainWindow): def __init__(self, path): super().__init__() self.setWindowTitle('Qt bug test') QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', path)[0] sys.exit()
if __name__ == '__main__': a = QtWidgets.QApplication([]) a.lastWindowClosed.connect(a.quit) app = App(path) app.show() sys.exit(a.exec())
Reproducible: Always
Steps to Reproduce: 1. Change the `path` variable to an existing path, which you can access, but which isn't your home directory 2. Run the example code using PyQt5 or PyQt6 installed through DNF
Actual Results: An open file dialog appears showing the contents of your home directory
Expected Results: An open file dialog appears showing the contents of `path`