'PyQt - Program to close window with model and view
Can anyone help me make a good code write and help me to understand the SIGNAL and SLOT with Model and View. With easy examples and codes i am new in Python and Qt5 and i try to learn in easy way. I have books with me to learn faster but books do it more complicated to learn and don't do it step by step.
Thank you.
import sys
from PyQt5 import QtWidgets as qtW
from PyQt5 import QtCore as qtC
class Model(qtW.QWidget, qtC.QObject):
quit = qtC.pyqtSignal(bool)
message_quit = "GOODBYE !"
def exit_window(self):
print(self.message_quit)
self.quit.emit(self.close())
class View(qtW.QWidget):
message = "Tape Text Here !"
message_show = "Your message shown here !"
button_show = "SHOW"
button_quit = "QUIT"
message_quit = "GOODBYE !"
def __init__(self):
super().__init__()
self.grid = qtW.QGridLayout()
self.setLayout(self.grid)
self.message_lineEdit = qtW.QLineEdit(self.message)
self.grid.addWidget(self.message_lineEdit, 0, 0)
self.message_label = qtW.QLabel(self.message_show)
self.grid.addWidget(self.message_label, 1, 0)
self.quit_button = qtW.QPushButton(self.button_quit)
self.grid.addWidget(self.quit_button, 2, 0)
class MainWindow(qtW.QMainWindow):
def __init__(self):
super().__init__()
self.view = View()
self.setCentralWidget(self.view)
self.model = Model()
self.view.quit_button.clicked.connect(self.model.exit_window)
self.show()
if __name__ == '__main__':
app = qtW.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
