Describe the bug
Editing the slider value using the text input field doesn't work correctly. If I input a non-integer value (having some nonzero decimal values), it is converted to an int.
To Reproduce
Steps to reproduce the behavior:
Create a QLabeledDoubleSlider with a range of 0-1 (if you have napari installed, you can use the opacity parameter of a layer)
Write 0.5 into the text field of the slider and press Enter.
Notice that the value is immediately converted to 0.0
Write 0.5 into the text field again.
This time the text field keeps this value, but the slider is not updated, meaning the slider value is in fact not updated (in napari you can easily verify it by checking the opacity value of the layer in the console)
Expected behavior
The input value shouldn't be casted to int
Screenshots
Original state:
After writing 0.5 and pressing Enter:
After writing 0.5 and pressing Enter again:
Desktop (please complete the following information):
Windows 11
PyQt5==5.15.9
Python 3.10.11
Potential fix:
I was able to fix this for my own project by adding the following function to QLabeledDoubleSlider:
Describe the bug Editing the slider value using the text input field doesn't work correctly. If I input a non-integer value (having some nonzero decimal values), it is converted to an int.
To Reproduce Steps to reproduce the behavior:
0.5
into the text field of the slider and press Enter.0.5
into the text field again.opacity
value of the layer in the console)Expected behavior The input value shouldn't be casted to int
Screenshots Original state: After writing 0.5 and pressing Enter: After writing 0.5 and pressing Enter again:
Desktop (please complete the following information):
Potential fix: I was able to fix this for my own project by adding the following function to
QLabeledDoubleSlider
:This works because
QLabeledDoubleSlider
inherits fromQLabeledSlider
, which converts the input value toint
before setting it to the slider.