Reputation: 6242
I have created a dialog with Qt Creator and then translated the .ui file to .py file with
pyuic5 dialog.ui -o dialog.py
The resulting code is the following
class Ui_dialog(object):
def setupUi(self, dialog):
dialog.setObjectName("dialog")
dialog.resize(976, 725)
self.verticalLayoutWidget = QtWidgets.QWidget(dialog)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(360, 210, 160, 80))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.retranslateUi(dialog)
QtCore.QMetaObject.connectSlotsByName(dialog)
def retranslateUi(self, dialog):
_translate = QtCore.QCoreApplication.translate
dialog.setWindowTitle(_translate("dialog", "Dialog"))
self.pushButton.setText(_translate("dialog", "PushButton"))
Now I'm trying to display the dialog from my main window with
dialog = QDialog()
dialog.ui = Ui_dialog()
dialog.ui.setupUi(self)
dialog.show()
dialog.exec_()
The dialog is shown, but it's empty so there's no button or any other widgets I tried!?
Upvotes: 2
Views: 1184
Reputation: 243887
Ui_Dialog's setupUi method requires a widget to fill in, and in your case you should change the following:
dialog.ui.setupUi(self)
to:
dialog.ui.setupUi(dialog)
Upvotes: 2