I am trying to add an custom dialog to acquire datetime objects from the user.
I created a main Gui (MainWindowStart3.py) and a dialog window (DateAndtimePicker.py) via qtdesigner, converted them to py and imported those in the main python file with:
from MainWindowStart3 import Ui_MainWindow
from DateAndTimePicker import Ui_Dialog
I create two classe: - for the dialog:
class DialogInterface (QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self,parent)
# self.ui = Ui_Dialog
# self.ui.setupUi(self)
self.setUi(self)
- for the MainWindow:
class UserInterface (Ui_MainWindow):
def addFunctions(self, MainWindow):
self.pushButton.clicked.connect(self.do_something)
self.pushButton_2.clicked.connect(self.do_something)
self.pushButton_3.clicked.connect(self.StartCharging)
self.pushButton_4.clicked.connect(self.stop_charging)
self.pushButton_5.clicked.connect(self.do_something)
self.pushButton_6.clicked.connect(self.do_something)
self.pushButton_7.clicked.connect(self.do_something)
self.pushButton_8.clicked.connect(self.do_something)
self.pushButton_9.clicked.connect(self.handleDialogWindow)
...
handleDialogWindow is the function to create the dialog window:
def handleDialogWindow(self):
dialog = DialogInterface(self)
result = dialog.exec_()
However, when I click in the GUI on that button, I get the following error message:
Traceback (most recent call last): File "RasPiInterfacer.py", line 134, in handleDialogWindow dialog = DialogInterface(self) File RasPiInterfacer.py", line 24, in init QtWidgets.QDialog.init(self,parent) TypeError: QDialog(parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'UserInterface'
line 134 corresponds to dialog = DialogInterface(self)
line 24 to QtWidgets.QDialog.__init__(self,parent)
I am new to GUI and dialogs and do not see where the error. My approach is inspired by the answers of this stackoverflow question.
Thank you very much for your time and patience with me in advance :-)
17-09-04: Is there any information I should add for you guys to ease finding the solution for my problem?
17-09-07: I did some changes to the code and now the dialog appears. Sadly I do not understand why this works now.
I changed the import statement of the dialog:
from DateAndTimePicker import Ui_Dialog as Form
And I made changes to the function called with
self.pushButton_9.clicked.connect(self.handleDialogWindow)
it now reads:
def handleDialogWindow(self):
dialog = QtWidgets.QDialog()
dialog.ui = Form()
dialog.ui.setupUi(dialog)
dialog.exec_()
dialog.show()
And now it works. How and Why? Thanks