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

Dragging the bar on range sliders causes a crash with PyQt6 #107

Closed sfhbarnett closed 2 years ago

sfhbarnett commented 2 years ago

Describe the bug Dragging the bar (as opposed to the handles at the end) causes a crash with PyQt6 (and not PyQt5) with the following message:

  File "/Users/sbarnett/opt/anaconda3/envs/PyV2/lib/python3.9/site-packages/superqt/sliders/_generic_range_slider.py", line 149, in mouseMoveEvent
    delta = self._clickOffset - self._pixelPosToRangeValue(self._pick(ev.pos()))
AttributeError: 'QMouseEvent' object has no attribute 'pos'

Seemingly this is the result of a change in the Qt API https://stackoverflow.com/questions/67496362/qmouseevent-object-has-no-attribute-pos

A fix is to change ev.pos() to ev.position() on line 149 in _generic_range_slider.py. I'd do this and make a pull request but this breaks backwards compatibility with PyQt5 and I don't know how to maintain that (or if there's a way).

To Reproduce Run the labeled.py example script with PyQt6 and click and drag the bar of a slider

Expected behavior Slider bar drags

Screenshots Screenshots and GIFS are much appreciated when reporting visual bugs.

Desktop (please complete the following information):

tlambert03 commented 2 years ago

thanks!

A fix is to change ev.pos() to ev.position() on line 149 in _generic_range_slider.py. I'd do this and make a pull request but this breaks backwards compatibility with PyQt5 and I don't know how to maintain that (or if there's a way).

that would be great thanks!

you can make a small compatibility function ... something like:

def _event_position(event):
    return event.pos() if hasattr(event, 'pos') else event.position()
sfhbarnett commented 2 years ago

Great thanks! I learned something new today

Czaki commented 2 years ago

close?