繁体   English   中英

如何从QDialog打开QTableView

[英]How to open a QTableView from a QDialog

我有一个显示登录表单的QDialog。 当用户输入详细信息并单击“确定”按钮时,我想关闭QDialog并打开一个QTableView,其中包含用户输入的登录详细信息。

我试图将“确定”按钮连接到一个关闭QDialog并显示QTableView的函数,但我的QTableView出现半秒钟,程序以“进程以退出代码0结束”结束

谢谢 !

    class TableViewGUI(QAbstractTableModel):
    def __init__(self, user_id, mdp, profile):
    QAbstractTableModel.__init__(self)
    [...]

    class Dialog(QDialog):
    def __init__(self, parent=None):
         super(Dialog, self).__init__(parent)
         [...]

    self.button.accepted.connect(self.openTableView)

    def openTableView(self):
         #data input by the user in the QDialog form
         id = self.input_id.text()
         password = self.input_password.text()
         profile = str(self.comboBox_profile.currentText())

         model = TableViewGUI(id, password, profile)
         view = QTableView()
         view.setModel(model)
         self.close() #Close the QDialog
         view.show() #Open the QTableView

if __name__ == '__main__':
     app = QApplication(sys.argv)
     dialog = Dialog()
     dialog.show()
     sys.exit(app.exec_())

一旦openTableView方法结束, modelview对象将被销毁,因为它们仅在方法范围内。 追加self. 在他们面前,就像这样:

    def openTableView(self):
         #data input by the user in the QDialog form
         id = self.input_id.text()
         password = self.input_password.text()
         profile = str(self.comboBox_profile.currentText())

         self.model = TableViewGUI(id, password, profile)
         self.view = QTableView()
         self.view.setModel(self.model)
         self.close() #Close the QDialog
         self.view.show() #Open the QTableView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM