Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hubutui opened this issue Dec 6, 2021 · 2 comments
Closed

Comments

@hubutui
Copy link

hubutui commented Dec 6, 2021

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
Copy link

Decodetalkers commented Jan 4, 2022

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

@grulja
Copy link
Collaborator

grulja commented Jul 28, 2022

Duplicate of #104.

@grulja grulja closed this as completed Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants