How does Signal and slot works in this code
Solved
Qt for Python
-
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("My App") button = QPushButton("Press Me!") button.setCheckable(True) button.clicked.connect(self.the_button_was_toggled) # Set the central widget of the Window. self.setCentralWidget(button) def the_button_was_toggled(self, checked): # from where value of variable checked is coming and how? print("Checked?", checked) app = QApplication(sys.argv) window = MainWindow() window.show() app.exec()
How does this code know the state of the button's checked value. From where it is accessing variable buttons and how
-
@Anmol Just look at the signal documentation: https://doc.qt.io/qt-6/qabstractbutton.html#clicked
As you can see the signal has checked parameter which is passed to the slot. -