Python Forum
[PyQt] PyQT5: Open QFiledialog in a Dialog which was create in qt designer
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] PyQT5: Open QFiledialog in a Dialog which was create in qt designer
#1
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
Reply
#2
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() ?
Reply
#3
(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
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#4
None works fine :)

fileName = QFileDialog.getSaveFileName(None, 'Dialog Title', home, file_filter)
thx :)
Reply
#5
(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
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there is a printer dialog box in PySimpleGUI shaunfish 2 1,582 Aug-22-2022, 07:29 PM
Last Post: deanhystad
  QT Designer Krissstian 4 1,639 May-26-2022, 09:45 AM
Last Post: Krissstian
  Qt Designer : help document viewer error. davediamond 2 1,543 Apr-14-2022, 10:38 AM
Last Post: davediamond
  GUI programming PyQt 5 + Qt Designer flash77 9 2,639 Mar-19-2022, 10:31 AM
Last Post: flash77
  How a QMainWindow can open a dialog? panoss 4 3,472 Feb-03-2022, 04:33 PM
Last Post: panoss
  How can I create a new tag with PyQt5? nickzsche 2 1,445 Jan-12-2022, 06:10 PM
Last Post: Axel_Erfurt
  [PyQt] QT5 Designer Drawing greenhorn1 1 2,511 Dec-30-2021, 05:12 PM
Last Post: deanhystad
  [Tkinter] question for a tkinter dialog box RobertAlvarez424 2 2,203 Aug-25-2021, 03:08 PM
Last Post: RobertAlvarez424
  [Tkinter] cancelling open dialog gives empty string rwahdan 2 3,307 Jul-17-2021, 09:17 PM
Last Post: steve_shambles
  Installed Designer - Helpf Files for "assistant" are missing Valmont 0 1,987 Mar-22-2021, 11:09 AM
Last Post: Valmont

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020