pyqt5对话框没有显示任何小部件

时间:2017-12-06 09:19:09

标签: python pyqt5

我已经使用Qt Creator创建了一个对话框,然后使用

将.ui文件转换为.py文件
 pyuic5 dialog.ui -o dialog.py

结果代码如下

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"))

现在我正在尝试使用

在主窗口中显示对话框
dialog = QDialog()
dialog.ui = Ui_dialog()
dialog.ui.setupUi(self)
dialog.show()
dialog.exec_()

显示对话框,但它是空的,所以没有按钮或我试过的任何其他小部件!?

1 个答案:

答案 0 :(得分:1)

Ui_Dialog的setupUi方法需要填充小部件,在您的情况下,您应该更改以下内容:

<%= select_tag :user_id, options_for_select(@users.map{|u| [u&.account_code+" "+u&.name, u.account_code] }) %>

为:

dialog.ui.setupUi(self)