Python Forum
[PyQt] PyQT5: Open QFiledialog in a Dialog which was create in qt designer - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] PyQT5: Open QFiledialog in a Dialog which was create in qt designer (/thread-3111.html)



PyQT5: Open QFiledialog in a Dialog which was create in qt designer - nieselfriem - Apr-29-2017

I create a dilaog in Qt Designer and I use PyQT5. After a selcetion of users and the ouput format, I will open a Filedialog to chouse the Filename and the path. But the problem is, that the Dilaog is inherit by object and the Filedialog need in the first parameter a QWidget

My CreateReportDialog:

[code]from PyQt5 import QtCore, QtGui, QtWidgets
from Database.DatabaseOperations import *
from rebezcheck_main import *

class CreateReport_Dialog(object):

    def __init__(self):
        self.ownerId = None
        self.firmId = None
        self.format = None


    def setupUi(self, createreport):
        createreport.setObjectName("Dialog")
        createreport.resize(400, 300)
....
    def createReport(self):
        msgbx = DataChangeMsgBx()
        check_input_list = self.check_input()
        if len(check_input_list) > 0:
            error_strg = "\n".join(check_input_list)
            msgbx.checkInputsMsgBx(error_strg)
        else:
            fileName = QFileDialog.getSaveFileName(self, 'Dialog Title', '/path/to/default/directory', selectedFilter='*.txt') # Error_Message
            if fileName:
                print("filename")[/code]
If I ty to open this Dialog I get the errormessage:

[inline][
TypeError: getSaveFileName(parent: QWidget = None, caption: str = '', directory: str = '', filter: str = '', initialFilter: str = '', options: Union[QFileDialog.Options, QFileDialog.Option] = 0): argument 1 has unexpected type 'CreateReport_Dialog'
/inline]

The function in my mainwindow to Open this dialog:

def showCreateReportDialog(self):
       createReportDialog = QtWidgets.QDialog()
       ui = CreateReport_Dialog()
       ui.setupUi(createReportDialog)
       createReportDialog.exec_()
I understand the problem but I don't know how I can fix them

Greets niesel


RE: PyQT5: Open QFiledialog in a Dialog which was create in qt designer - Larz60+ - Apr-29-2017

It looke to me (without being able to run code) as though createReportDialog returns nothing
which means it automatically returns None.
Is None a valid type for ui.setupUi() ?


RE: PyQT5: Open QFiledialog in a Dialog which was create in qt designer - volcano63 - Apr-29-2017

(Apr-29-2017, 01:10 PM)nieselfriem Wrote:
TypeError: getSaveFileName(parent: QWidget = None, .....): argument 1 has unexpected type 'CreateReport_Dialog'
The type of the first parameter is expected to be QWidget, you pass self - which inherits from object

As far as I remember - no PyQt in 2 years -, in many cases it allows None as a parent argument, but if it is not None - it must inherit from QWidget


RE: PyQT5: Open QFiledialog in a Dialog which was create in qt designer - nieselfriem - Apr-30-2017

None works fine :)

fileName = QFileDialog.getSaveFileName(None, 'Dialog Title', home, file_filter)
thx :)


RE: PyQT5: Open QFiledialog in a Dialog which was create in qt designer - volcano63 - Apr-30-2017

(Apr-30-2017, 07:38 PM)nieselfriem Wrote: None works fine :)

fileName = QFileDialog.getSaveFileName(None, 'Dialog Title', home, file_filter)
thx :)

I've still got it Dance You are welcome