Skip to content

Commit

Permalink
Add mappings for deprecated QDropEvent pos and posF methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Aug 16, 2023
1 parent 3ba97e3 commit f5d2fe4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def movePositionPatched(
return movePosition(self, operation, mode, n)
QTextCursor.movePosition = movePositionPatched

# Fix https://github.com/spyder-ide/qtpy/issues/394
if PYQT5 or PYSIDE2:
# Part of the fix for https://github.com/spyder-ide/qtpy/issues/394
from qtpy.QtCore import QPointF as __QPointF
QNativeGestureEvent.x = lambda self: self.localPos().toPoint().x()
QNativeGestureEvent.y = lambda self: self.localPos().toPoint().y()
Expand All @@ -160,7 +160,11 @@ def movePositionPatched(
QMouseEvent.position = lambda self: self.localPos()
QMouseEvent.globalPosition = lambda self: __QPointF(
float(self.globalX()), float(self.globalY()))

# Follow similar approach for `QDropEvent` and child classes
QDropEvent.position = lambda self: self.posF()
if PYQT6 or PYSIDE6:
# Part of the fix for https://github.com/spyder-ide/qtpy/issues/394
for _class in (QNativeGestureEvent, QEnterEvent, QTabletEvent, QHoverEvent,
QMouseEvent):
for _obsolete_function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY'):
Expand All @@ -175,3 +179,6 @@ def movePositionPatched(
QSinglePointEvent.globalX = lambda self: self.globalPosition().toPoint().x()
QSinglePointEvent.globalY = lambda self: self.globalPosition().toPoint().y()

# Follow similar approach for `QDropEvent` and child classes
QDropEvent.pos = lambda self: self.position().toPoint()
QDropEvent.posF = lambda self: self.position()
10 changes: 9 additions & 1 deletion qtpy/tests/test_qtgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None:
qtbot.mouseDClick(window, QtCore.Qt.LeftButton)

# the rest of the functions are not actually tested
for _class in ('QNativeGestureEvent', 'QEnterEvent', 'QTabletEvent'):
# QSinglePointEvent child classes checks
for _class in (
'QSinglePointEvent', 'QNativeGestureEvent', 'QEnterEvent', 'QTabletEvent'
):
for _function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY',
'position', 'globalPosition'):
assert hasattr(getattr(QtGui, _class), _function)
# QHoverEvent checks
for _function in ('pos', 'x', 'y', 'position'):
assert hasattr(QtGui.QHoverEvent, _function)
# QDropEvent and child classes checks
for _class in ('QDropEvent', 'QDragMoveEvent', 'QDragEnterEvent'):
for _function in ('pos', 'posF', 'position'):
assert hasattr(getattr(QtGui, _class), _function)


@pytest.mark.skipif(not (PYSIDE2 or PYSIDE6), reason="PySide{2,6} specific test")
Expand Down

0 comments on commit f5d2fe4

Please sign in to comment.