[Interest] Curious behaviour of slider/spin when controlled by keyboard

Shriramana Sharma samjnaa at gmail.com
Thu Nov 15 18:58:30 CET 2012

Hello. I ran into a curious behaviour when writing a PyQt program but
later found out that it is not particular to PyQt but exists in C++/Qt
as well.

I've attached minimal test cases. I note that in both the C++/PyQt
minimal examples the bug is reproducible only when there is only a
slider + a doubleSpin ("2-widgets") and not when there is also an
integer spin ("3-widgets"). When there is an integer spin in addition
("3-widgets"), there is some lagging behind between the widgets (as
can be seen visually as well as in the debug output) but it gets
through and I'm able to run the whole range using the keyboard, but if
there is no integer spin and only the double spin with the slider
("2-widgets") , the problem surfaces. It is clear this has something
to do with the limitations of floating point data type (but I'm
surprised it would surface even when only two decimal placesare

I presume others would have encountered such situations and would like
advice on how to work around this limitation.

The problem is as described below:

1. Let the focus be either on the slider or the spin. (The default
slider/spin value is 0.50.)
3. Press up-arrow key to increase the slider/spin value.

The value will not increase past 0.56.

4. Press down-arrow key to decrease the slider/spin value until 0.30.
5. Press down-arrow once more.

The value jumps down from 0.30 to 0.28 even though the precision is set at 0.01.

6. Press up-arrow.

The value will now not rise above 0.28.

7. Adjust the slider position using the mouse.

The value can change to any value in its full range from 0.00 to 1.00.

8. Adjust the slider using the mouse to go beyond 0.60.
9. Press down-arrow to decrease the value until 0.59.
10. Press down-arrow once more.

11. The value jumps down to 0.56.
12. It will no longer go above 0.56 using the keyboard (as before).

Shriramana Sharma
-------------- next part --------------
A non-text attachment was scrubbed...
Name: slider-minimal-test.tar.gz
Type: application/x-gzip
Size: 1696 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121115/4b5c2b0e/attachment.bin>

More information about the Interest mailing list