Looking at the implementation of QAbstractButton , I found the following lines of code:
if (!d->checkable || d->checked == checked) { if (!d->blockRefresh) checkStateSet(); return; }
where checkStateSet is a virtual function. QCheckBox overrides this value and emits the stateChanged() signal only if the state is changed. I have not tested this, but I think d->blockRefresh set to false if you call QCheckBox::setChecked( ... ) directly.
If so, that means you can subclass QCheckBox and override the checkStateSet() method as follows:
void MyCheckBox::checkStateSet() { QCheckBox::checkStateSet(); if( m_oldState == checkState() ) {
where the header file contains
private: Qt::CheckState m_oldState;
which should be initialized in Qt::Unchecked in the constructor.
source share