PDA

View Full Version : Using QAbstractButton:isChecked() for the QAbstractButton auto repeat function



schall_l
3rd May 2010, 00:44
I have a checkable button i.e. QAbstractButton::setCheckable(true)

Now I would like to perform a cyclic action when the button is in it checked state.

There is QAbstractButton::setAutoRepeat(), QAbstractButton::autoRepeatDelay() and QAbstractButton::autoRepeatInterval() that are permiting an autorepeat behavior if the user holds the button down.

Is there a possibility to make this behavior to happen not on QAbstractButton::isDown() but on QAbstractButton:isChecked()?

norobro
3rd May 2010, 18:31
Try this:
instantiate a QTimer;
connect the QTimer::timeout() to a slot that performs your cyclic action;
connect the button->pressed() signal to a custom slot where if(button->isChecked()) {start the timer with the desired interval;} else {stop the timer;}

From looking at the sources, the above is essentially what happens when you have QAbstractButton::setAutoRepeat() and QAbstractButton::autoRepeatInterval() set. When the left mouse button is held down a timer is instantiated that emits the button's signals at the specified interval.

HTH