如您所见,我已经将第一个按钮连接到名为“ popup”的方法,该方法需要用代码填充才能d出第二个窗口。我该怎么做呢?
为主窗口(
MyForm)进行处理的方式几乎相同。
与往常一样,您为第二个对话框的QtDesigner代码编写了一个包装器类(就像使用一样
MyForm)。叫它
MyPopupDialog。然后,在您的
popup方法中,创建一个实例,然后使用
exec_()或
show()取决于您是否需要模式对话框或无模式对话框来显示您的实例。(如果您不熟悉“模态/无模式”概念,则可以参考文档。)
因此,总体情况可能如下所示(进行了一些修改):
# Necessary importsclass MyPopupDialog(QtGui.QDialog): def __init__(self, parent=None): # Regular init stuff... # and other things you might wantclass MyForm(QtGui.QDialog): def __init__(self, parent=None): # Here, you should call the inherited class' init, which is QDialog QtGui.QDialog.__init__(self, parent) # Usual setup stuff self.ui = Ui_Dialog() self.ui.setupUi(self) # Use new style signal/slots self.ui.pushButton.clicked.connect(self.popup) # Other things... def popup(self): self.dialog = MyPopupDialog() # For Modal dialogs self.dialog.exec_() # Or for modeless dialogs # self.dialog.show()if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp= MyForm() myapp.show() sys.exit(app.exec_())
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)