Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add mappings for deprecated QDropEvent pos and posF methods #445

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
8 changes: 8 additions & 0 deletions qtpy/tests/test_qtgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,21 @@ def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None:
qtbot.mouseDClick(window, QtCore.Qt.LeftButton)

# the rest of the functions are not actually tested
# QSinglePointEvent (Qt6) child classes checks
for _class in ('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")
def test_qtextcursor_moveposition():
Expand Down
Loading