Reputation: 1069
I make a relation between QSpinbox and QSlider.
QSpinbox has a range -10.0 to 10.0, and QSlider has a range -100 to 100.
So, the value of QSlider divided by 10 is connect to QSpinbox, and vice versa.
I use "valueChanged()" SIGNAL to each other.
And I want to type "3.5" in QSpinbox, in this case when I type just "3", QSpinbox's "valueChanged" change QSlider's value, and QSlider do again. So, QSpinbox lose it's focus.
I can't type "3.5" in one shot.
"valueChanged()" SIGNAL works too diligently :)
How can I solve this issue?
Upvotes: 1
Views: 1990
Reputation: 92559
The valueChanged()
signal is indeed meant to fire actively as it is being changed. If you want a signal fired when editing has finished, there is a signal specifically for that called editingFinished
: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractspinbox.html#editingFinished
You may have overlooked it because its a member of the superclass QAbstractSpinBox. Note that this signal will fire once the widget loses focus or the user hits enter. If that is not the behavior you want either, then the only remaining option is to use a QTimer with a short delay that restarts everytime valueChanged
fires, and once the user waits long enough the timeout will actually then update your slider.
I also noticed that you are trying to use non-integer values with a QSpinBox, which is designed for ints. You might want to try a QDoubleSpinBox that is designed for floating precision. The valueChange()
might behave slightly better as its expecting the decimal. Though I am just making a guess as I haven't tested it: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdoublespinbox.html
Upvotes: 3