Bug 2258467 - PyQt6 and PyQt5 ignore "dir" argument in QFileDialog.getOpenFileName
Summary: PyQt6 and PyQt5 ignore "dir" argument in QFileDialog.getOpenFileName
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: python-pyqt6
Version: 38
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Onuralp SEZER
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-01-15 14:20 UTC by Michael Clerx
Modified: 2024-05-27 13:29 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2024-05-27 13:29:10 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Michael Clerx 2024-01-15 14:20:32 UTC
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`

Comment 1 Sandro Mani 2024-02-16 22:25:05 UTC
Cannot reproduce this with either python3-pyqt6-6.6.1-4.fc40 or python3-qt5-5.15.10-4.fc40. Can you reproduce this with a clean install (i.e. in a virtualbox)?

Comment 2 Michael Clerx 2024-02-20 19:49:30 UTC
I cannot reproduce this in a clean install of Fedora 39.
But I can reproduce it in a clean install of 38, and then all the way back to 32 (but not in 31).

I'm glad it works again in 39, but might be good to have a test or something to make sure it doesn't reoccur in newer versions?

Comment 3 Sandro Mani 2024-02-28 13:43:40 UTC
> But I can reproduce it in a clean install of 38, and then all the way back to 32 (but not in 31).

Clean and up-to-date F38?

Comment 4 Michael Clerx 2024-02-28 13:59:40 UTC
Yes I can recreate the problem with

1. Clean install of F38
2. dnf install python3-pyqt5 (or 6)

and with

1. Clean install of F38
2. dnf install python3-pyqt5 (or 6)
3. dnf update -y

Comment 5 Sandro Mani 2024-05-27 13:29:10 UTC
F38 ist EOL.


Note You need to log in before you can comment on or make changes to this bug.