FedoraQt / QGnomePlatform

QPlatformTheme for a better Qt application inclusion in GNOME
GNU Lesser General Public License v2.1
262 stars 38 forks source link

PySide2.QtWidgets.QFileDialog.getOpenFileName's args `dir` is not working #91

Closed hubutui closed 2 years ago

hubutui commented 2 years ago

Minimal code to reproduce:

# main.py
import sys

from PySide2.QtWidgets import (QApplication, QFileDialog, QMainWindow,
                               QMessageBox)

from ui_mainwindow import Ui_MainWindow

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.pushButton.clicked.connect(self.onButtonClicked)

    def onTaskFinished(self, message):
        QMessageBox.information(self, "info", message)

    def onButtonClicked(self):
        fileName = QFileDialog.getOpenFileName(
            self, "Open File", "/home", "Images (*.png *.xpm *.jpg)"
        )

if __name__ == "__main__":
    app = QApplication([])
    window = MainWindow()
    window.show()

    sys.exit(app.exec_())
# ui_mainwindow.py

################################################################################
## Form generated from reading UI file 'mainwindow.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(806, 551)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.pushButton = QPushButton(self.centralwidget)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(224, 132, 271, 121))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 806, 47))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)

    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(
            QCoreApplication.translate("MainWindow", u"MainWindow", None)
        )
        self.pushButton.setText(
            QCoreApplication.translate("MainWindow", u"Click Me", None)
        )

    # retranslateUi

I set dir="/home" in QFileDialog.getOpenFileName, by default the dialog should open /home, but it shows recent files instead. Also, the dialog is behind the main window, not on top.

OS: ArchLinux Qt: 5.15.2+kde+r262-1 PySide2: 5.15.2-3 qgnomeplatform: 0.8.3-1 adwaita-qt: 1.4.1-2

Decodetalkers commented 2 years ago

Same problem, @grulja , please solve it, thinks a lot

grulja commented 2 years ago

Duplicate of https://github.com/FedoraQt/QGnomePlatform/issues/104.