tags:

views:

287

answers:

2

Do I miss something or there is really no (ready / built-in) way to programmatically change the state of a QCheckBox without emitting the "void stateChanged ( int state )" signal?

The above-mentioned signal is emitted regardless of whether "void setCheckState ( Qt::CheckState state )" was called or the user changed the state via the ui, and there is no "stateEdited" signal like with the QLineEdit.

So, if there is no ready way to differentiate between programmatic and user-induced changes to the state of the QCheckBox, and the only options are subclassing / adding the "stateEdited" signal or fiddling with "void QObject::blockSignals( bool block )", why does this have to be so, i.e., is it an (some sort of) inconsistency (in Qt)?

Thanks in advance, and forgive my English.

+1  A: 

If you want to

programatically change the state of a QCheckBox

use setCheckState method.

P.S. I do not understand what does it mean

change the state of a QCheckBox ... emitting a "void stateChanged ( int state )" signal

Probably you should read Signals and Slots topic more carefully.

kemiisto
mlvljr
I get your point. I see only one option: create and use instead of QCheckBox class your own class which is based on QCheckBox (subclass it) and then define new method (or redifine setChecked). Your method should differ from one of QCheckBox (http://qt.gitorious.org/qt/qt/blobs/master/src/gui/widgets/qcheckbox.cpp) only in the last line of code. You don't need emit stateChanged(state);But I don't think it's good solution... Why do you need such different behavior?
kemiisto
There seems to be a need to set up some widgets whose signals are already connected without emitting them (signals). Anyway, I can always use "QObject::blockSignals( bool block )". P.S. (off.) Your web page at <http://sites.google.com/site/kemiisto/home> is in Russian, are you really from there?
mlvljr
Aha! blockSignals seems to be a solution. So you found it by yourself. =)P.S. Yes, I'm Russian by origin.
kemiisto
Actually I kinda new it beforehand, just was wondering if there was an elegant possibility buried somewhere up the inheritance tree :) Thanks, в любом случае.
mlvljr
+4  A: 

If you only need to be informed of user input, listen to

QAbstractButton::clicked( bool checked );

Otherwise connect to

QAbstractButton::toggled( bool checked );

or

QCheckBox::stateChanged( int state);
TimW
That's the one, thanks!
mlvljr