I have this code in which I create a number of QCheckBoxes through a loop:
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("My App")
self.dbutton = QPushButton("Press ME")
self.dbutton.setEnabled(False)
self.button_state = 0
self.checkbox_layout = QFormLayout()
for i in range(5):
self.checkbox = QCheckBox()
self.checkbox.toggled.connect(self.enable_button)
self.series_info = QLabel(str(i))
self.checkbox_layout.addRow(self.checkbox, self.series_info)
layout = QVBoxLayout()
layout.addWidget(self.dbutton)
layout.addLayout(self.checkbox_layout)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
def enable_button(self):
print(self.checkbox.isChecked())
What I'm trying to do is to get the state of the specific QCheckBox that is triggering the signal to the enable_button
slot, but I'm getting this weird behavior, where The state is show as False
until all buttons are enable, but then it immediately flips to False
as soon as just one of them is unmarked, as shown in the gif below. How can I fix this?