pyapp-kit / superqt

Missing widgets and components for Qt-python
https://pyapp-kit.github.io/superqt/
BSD 3-Clause "New" or "Revised" License
210 stars 38 forks source link

QLabeledDoubleSlider text input broken #166

Closed bauerdavid closed 1 year ago

bauerdavid commented 1 year ago

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:

  1. Create a QLabeledDoubleSlider with a range of 0-1 (if you have napari installed, you can use the opacity parameter of a layer)
  2. Write 0.5 into the text field of the slider and press Enter.
  3. Notice that the value is immediately converted to 0.0
  4. Write 0.5 into the text field again.
  5. 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: image After writing 0.5 and pressing Enter: image After writing 0.5 and pressing Enter again: image

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:

def _setValue(self, value: float):
    self._slider.setValue(value)

This works because QLabeledDoubleSlider inherits from QLabeledSlider, which converts the input value to int before setting it to the slider.

tlambert03 commented 1 year ago

thanks @bauerdavid ... looks like this was a regression introduced in https://github.com/pyapp-kit/superqt/pull/106

will have a fix soon