View Full Version : QSpinBox on_valueChanged
martinb0820
23rd September 2008, 19:22
How can I distinguish between the user changing the value of a spin box and the program changing the value? (Different things happen in the two cases...)
A workaround is to test whether, in the on_valueChanged() method, the spin box value matches the current value of the variable it's setting, but this adds overhead I would like to avoid.
Thanks,
Martin
RThaden
23rd September 2008, 22:52
Maybe http://doc.trolltech.com/4.4.1/qabstractspinbox.html#editingFinished is your friend.
Regards,
Rainer
martinb0820
24th September 2008, 19:30
Maybe http://doc.trolltech.com/4.4.1/qabstractspinbox.html#editingFinished is your friend.
Regards,
Rainer
Hi Rainer,
That was an interesting possibility. I don't think I gave enough information in the original question. Basically the program needs to take an action on each value change, rather than when the edit is entirely complete.
So what I need is a way to either cause on_valueChanged events to only occur due to user input, or to check within on_valueChanged whether the user or the program caused the change.
Thanks,
Martin
martinb0820
15th December 2008, 02:31
I figured out an approach, but didn't get around to posting it. Basically, I wanted to have a spinBox and a slider "coupled" so that, if one is moved, the other changes appropriately. However, changing the spinBox programatically because the user changed the slider position or clicked on a button also invokes the on_ method for the spinBox, causing the value to be "stuck".
All it took was a flag to indicate whether the user changed the value via the slider or buttons; the flag is set to true in the slider and button on_ slots. If the flag says the user didn't change the value, i.e. it was changed programatically, the on_ slot for the spinBox doesn't do anything.
Martin
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.