Advertisement
Artem78

Qt dialog destructor bug

Jan 11th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog, QPushButton, QLineEdit, QFormLayout
  2.  
  3. class MainWnd(QMainWindow):
  4.  
  5.     def __init__(self):
  6.         super().__init__()
  7.        
  8.         self.button = QPushButton('Open dialog')
  9.         self.button.clicked.connect(self.show_dialog)
  10.         self.setCentralWidget(self.button)
  11.        
  12.         self.dlg_widget = QLineEdit('Close dialog and try to open again')
  13.        
  14.     def show_dialog(self):
  15.         dlg = Dlg(self)
  16.         dlg.exec_()
  17.  
  18. class Dlg(QDialog):
  19.    
  20.     def __init__(self, parent=None):
  21.         super().__init__(parent)
  22.        
  23.         self.layout = QFormLayout()
  24.         self.layout.addWidget(self.parentWidget().dlg_widget)
  25.         self.setLayout(self.layout)
  26.        
  27.  
  28. app = QApplication([])
  29. mwnd = MainWnd()
  30. mwnd.show()
  31. exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement