Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.x
-
None
-
37b47ebf9 (dev)
Description
The Qt::stateChanged signal is currently emitted with a value of type integer, even though the signal documentation says that the state parameter "contains the checkbox's new Qt::CheckState." It seems like this signal should be emitted with a value of type Qt::CheckState instead. The two spots where this signal is emitted in qcheckbox.cpp, it's emitted with a Qt::CheckState value that's implicitly converted to an integer. For comparison, the QScroller::stateChanged signal, which is similar to QCheckBox::stateChanged, is emitted with a QScroller::State value rather than an integer.
The integer parameter of QCheckBox::stateChanged is particularly problematic when working with PyQt 6, because PyQt 6 enforces type checking for enums, which means that integers will never compare equal to any Qt::CheckState value. In other words, if the following slot is connected to QCheckBox::stateChanged in PyQt 6
def onStateChanged(state): if state == Qt.CheckState.Checked: print("Checked") elif state == Qt.CheckState.Unchecked: print("Unchecked") elif state == Qt.CheckState.PartiallyChecked: print("Partially checked") else: print("Unrecognized value")
then it will always print "Unrecognized value" because it will be called with 0, 1, or 2, instead of Checked, Unchecked, or PartiallyChecked. To work around this, comparisons need to be done against, e.g. Qt.CheckState.Checked.value (the ".value" at the end will convert the enum into an integer) instead.
Q_SIGNALS:
void stateChanged(int);