簡體   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