From e1515f82fbda31afcdfc24513e4fb18b019fea54 Mon Sep 17 00:00:00 2001 From: stsav012 Date: Fri, 24 Mar 2023 17:04:53 +0300 Subject: [PATCH 1/5] Fix #394 for all children of `QSinglePointEvent` --- qtpy/QtGui.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 35a83eab..7ee57f32 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -90,9 +90,9 @@ def movePositionPatched( QMouseEvent.position = lambda self: __QPointF(float(self.x()), float(self.y())) QMouseEvent.globalPosition = lambda self: __QPointF(float(self.globalX()), float(self.globalY())) if PYQT6 or PYSIDE6: - QMouseEvent.pos = lambda self: self.position().toPoint() - QMouseEvent.x = lambda self: self.position().toPoint().x() - QMouseEvent.y = lambda self: self.position().toPoint().y() - QMouseEvent.globalPos = lambda self: self.globalPosition().toPoint() - QMouseEvent.globalX = lambda self: self.globalPosition().toPoint().x() - QMouseEvent.globalY = lambda self: self.globalPosition().toPoint().y() + QSinglePointEvent.pos = lambda self: self.position().toPoint() + QSinglePointEvent.x = lambda self: self.position().toPoint().x() + QSinglePointEvent.y = lambda self: self.position().toPoint().y() + QSinglePointEvent.globalPos = lambda self: self.globalPosition().toPoint() + QSinglePointEvent.globalX = lambda self: self.globalPosition().toPoint().x() + QSinglePointEvent.globalY = lambda self: self.globalPosition().toPoint().y() From e13b3a5b7c5352850c1cc897d8597d1df2721ae4 Mon Sep 17 00:00:00 2001 From: stsav012 Date: Fri, 24 Mar 2023 17:04:53 +0300 Subject: [PATCH 2/5] Fix #394 for all children of `QSinglePointEvent` --- qtpy/QtGui.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 7ee57f32..4591f414 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -90,6 +90,10 @@ def movePositionPatched( QMouseEvent.position = lambda self: __QPointF(float(self.x()), float(self.y())) QMouseEvent.globalPosition = lambda self: __QPointF(float(self.globalX()), float(self.globalY())) if PYQT6 or PYSIDE6: + for _class in (QNativeGestureEvent, QEnterEvent, QTabletEvent, QHoverEvent, QWheelEvent, QMouseEvent): + for _obsolete_function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY'): + if hasattr(_class, _obsolete_function): + delattr(_class, _obsolete_function) QSinglePointEvent.pos = lambda self: self.position().toPoint() QSinglePointEvent.x = lambda self: self.position().toPoint().x() QSinglePointEvent.y = lambda self: self.position().toPoint().y() From af83b5655742507a0b138c0fdebe22b9a48451a1 Mon Sep 17 00:00:00 2001 From: stsav012 Date: Fri, 24 Mar 2023 22:28:29 +0300 Subject: [PATCH 3/5] Add position functions of `QNativeGestureEvent`, `QEnterEvent`, `QTabletEvent`, and `QHoverEvent` --- qtpy/QtGui.py | 21 +++++++++++++++++-- qtpy/tests/test_qtgui.py | 45 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 4591f414..68e86431 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -87,14 +87,31 @@ def movePositionPatched( # Fix https://github.com/spyder-ide/qtpy/issues/394 if PYQT5 or PYSIDE2: from qtpy.QtCore import QPointF as __QPointF - QMouseEvent.position = lambda self: __QPointF(float(self.x()), float(self.y())) + QNativeGestureEvent.x = lambda self: self.localPos().toPoint().x() + QNativeGestureEvent.y = lambda self: self.localPos().toPoint().y() + QNativeGestureEvent.position = lambda self: self.localPos() + QNativeGestureEvent.globalX = lambda self: self.globalPos().x() + QNativeGestureEvent.globalY = lambda self: self.globalPos().y() + QNativeGestureEvent.globalPosition = lambda self: __QPointF(float(self.globalPos().x()), + float(self.globalPos().y())) + QEnterEvent.position = lambda self: self.localPos() + QEnterEvent.globalPosition = lambda self: __QPointF(float(self.globalX()), float(self.globalY())) + QTabletEvent.position = lambda self: self.posF() + QTabletEvent.globalPosition = lambda self: self.globalPosF() + QHoverEvent.x = lambda self: self.pos().x() + QHoverEvent.y = lambda self: self.pos().y() + QHoverEvent.position = lambda self: self.posF() + # no `QHoverEvent.globalPosition`, `QHoverEvent.globalX`, nor `QHoverEvent.globalY` in the Qt5 docs + QMouseEvent.position = lambda self: self.localPos() QMouseEvent.globalPosition = lambda self: __QPointF(float(self.globalX()), float(self.globalY())) if PYQT6 or PYSIDE6: - for _class in (QNativeGestureEvent, QEnterEvent, QTabletEvent, QHoverEvent, QWheelEvent, QMouseEvent): + for _class in (QNativeGestureEvent, QEnterEvent, QTabletEvent, QHoverEvent, QMouseEvent): for _obsolete_function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY'): if hasattr(_class, _obsolete_function): delattr(_class, _obsolete_function) QSinglePointEvent.pos = lambda self: self.position().toPoint() + QSinglePointEvent.posF = lambda self: self.position() + QSinglePointEvent.localPos = lambda self: self.position() QSinglePointEvent.x = lambda self: self.position().toPoint().x() QSinglePointEvent.y = lambda self: self.position().toPoint().y() QSinglePointEvent.globalPos = lambda self: self.globalPosition().toPoint() diff --git a/qtpy/tests/test_qtgui.py b/qtpy/tests/test_qtgui.py index 787d7dba..d4e1c378 100644 --- a/qtpy/tests/test_qtgui.py +++ b/qtpy/tests/test_qtgui.py @@ -77,7 +77,7 @@ def test_enum_access(): @pytest.mark.skipif( sys.platform == 'darwin' and sys.version_info[:2] == (3, 7), reason="Stalls on macOS CI with Python 3.7") -def test_QMouseEvent_pos_functions(qtbot): +def test_QSomethingEvent_pos_functions(qtbot): """ Test `QMouseEvent.pos` and related functions removed in Qt 6, and `QMouseEvent.position`, etc., missing from Qt 5. @@ -101,8 +101,47 @@ def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None: window.setMinimumSize(320, 240) # ensure the window is of sufficient size window.show() - qtbot.mouseMove(window, QtCore.QPoint(42, 6 * 9)) - qtbot.mouseDClick(window, QtCore.Qt.LeftButton) + with qtbot.waitExposed(window): + qtbot.mouseMove(window, QtCore.QPoint(42, 6 * 9)) + qtbot.mouseDClick(window, QtCore.Qt.LeftButton) + + # the rest of the functions are not actually tested + assert QtGui.QNativeGestureEvent.pos is not None + assert QtGui.QNativeGestureEvent.x is not None + assert QtGui.QNativeGestureEvent.y is not None + assert QtGui.QNativeGestureEvent.globalPos is not None + assert QtGui.QNativeGestureEvent.globalX is not None + assert QtGui.QNativeGestureEvent.globalY is not None + assert QtGui.QNativeGestureEvent.position is not None + assert QtGui.QNativeGestureEvent.globalPosition is not None + assert QtGui.QEnterEvent.pos is not None + assert QtGui.QEnterEvent.x is not None + assert QtGui.QEnterEvent.y is not None + assert QtGui.QEnterEvent.globalPos is not None + assert QtGui.QEnterEvent.globalX is not None + assert QtGui.QEnterEvent.globalY is not None + assert QtGui.QEnterEvent.position is not None + assert QtGui.QEnterEvent.globalPosition is not None + assert QtGui.QTabletEvent.pos is not None + assert QtGui.QTabletEvent.x is not None + assert QtGui.QTabletEvent.y is not None + assert QtGui.QTabletEvent.globalPos is not None + assert QtGui.QTabletEvent.globalX is not None + assert QtGui.QTabletEvent.globalY is not None + assert QtGui.QTabletEvent.position is not None + assert QtGui.QTabletEvent.globalPosition is not None + assert QtGui.QHoverEvent.pos is not None + assert QtGui.QHoverEvent.x is not None + assert QtGui.QHoverEvent.y is not None + assert QtGui.QHoverEvent.position is not None + assert QtGui.QTabletEvent.pos is not None + assert QtGui.QTabletEvent.x is not None + assert QtGui.QTabletEvent.y is not None + assert QtGui.QTabletEvent.globalPos is not None + assert QtGui.QTabletEvent.globalX is not None + assert QtGui.QTabletEvent.globalY is not None + assert QtGui.QTabletEvent.position is not None + assert QtGui.QTabletEvent.globalPosition is not None @pytest.mark.skipif(not (PYSIDE2 or PYSIDE6), reason="PySide{2,6} specific test") From fac2382aa924e788c27352fe71dc472b1551dae5 Mon Sep 17 00:00:00 2001 From: stsav012 Date: Sat, 25 Mar 2023 00:08:41 +0300 Subject: [PATCH 4/5] Simplify the tests for the position functions of `Q...Event`, as @CAM-Gerlach suggested --- qtpy/tests/test_qtgui.py | 41 +++++----------------------------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/qtpy/tests/test_qtgui.py b/qtpy/tests/test_qtgui.py index d4e1c378..5bef40dc 100644 --- a/qtpy/tests/test_qtgui.py +++ b/qtpy/tests/test_qtgui.py @@ -106,42 +106,11 @@ def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None: qtbot.mouseDClick(window, QtCore.Qt.LeftButton) # the rest of the functions are not actually tested - assert QtGui.QNativeGestureEvent.pos is not None - assert QtGui.QNativeGestureEvent.x is not None - assert QtGui.QNativeGestureEvent.y is not None - assert QtGui.QNativeGestureEvent.globalPos is not None - assert QtGui.QNativeGestureEvent.globalX is not None - assert QtGui.QNativeGestureEvent.globalY is not None - assert QtGui.QNativeGestureEvent.position is not None - assert QtGui.QNativeGestureEvent.globalPosition is not None - assert QtGui.QEnterEvent.pos is not None - assert QtGui.QEnterEvent.x is not None - assert QtGui.QEnterEvent.y is not None - assert QtGui.QEnterEvent.globalPos is not None - assert QtGui.QEnterEvent.globalX is not None - assert QtGui.QEnterEvent.globalY is not None - assert QtGui.QEnterEvent.position is not None - assert QtGui.QEnterEvent.globalPosition is not None - assert QtGui.QTabletEvent.pos is not None - assert QtGui.QTabletEvent.x is not None - assert QtGui.QTabletEvent.y is not None - assert QtGui.QTabletEvent.globalPos is not None - assert QtGui.QTabletEvent.globalX is not None - assert QtGui.QTabletEvent.globalY is not None - assert QtGui.QTabletEvent.position is not None - assert QtGui.QTabletEvent.globalPosition is not None - assert QtGui.QHoverEvent.pos is not None - assert QtGui.QHoverEvent.x is not None - assert QtGui.QHoverEvent.y is not None - assert QtGui.QHoverEvent.position is not None - assert QtGui.QTabletEvent.pos is not None - assert QtGui.QTabletEvent.x is not None - assert QtGui.QTabletEvent.y is not None - assert QtGui.QTabletEvent.globalPos is not None - assert QtGui.QTabletEvent.globalX is not None - assert QtGui.QTabletEvent.globalY is not None - assert QtGui.QTabletEvent.position is not None - assert QtGui.QTabletEvent.globalPosition is not None + for _class in ('QNativeGestureEvent', 'QEnterEvent', 'QTabletEvent'): + for _function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY', 'position', 'globalPosition'): + assert hasattr(getattr(QtGui, _class), _function) + for _function in ('pos', 'x', 'y', 'position'): + assert hasattr(QtGui.QHoverEvent, _function) @pytest.mark.skipif(not (PYSIDE2 or PYSIDE6), reason="PySide{2,6} specific test") From bd1b013e6d3d9163d64bad17349895cba969df92 Mon Sep 17 00:00:00 2001 From: Anton Yablokov Date: Tue, 28 Mar 2023 07:55:55 +0300 Subject: [PATCH 5/5] Apply code style suggestions by @ccordoba12 Co-authored-by: Carlos Cordoba --- qtpy/QtGui.py | 16 ++++++++++------ qtpy/tests/test_qtgui.py | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 68e86431..d51540df 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -92,20 +92,24 @@ def movePositionPatched( QNativeGestureEvent.position = lambda self: self.localPos() QNativeGestureEvent.globalX = lambda self: self.globalPos().x() QNativeGestureEvent.globalY = lambda self: self.globalPos().y() - QNativeGestureEvent.globalPosition = lambda self: __QPointF(float(self.globalPos().x()), - float(self.globalPos().y())) + QNativeGestureEvent.globalPosition = lambda self: __QPointF( + float(self.globalPos().x()), float(self.globalPos().y())) QEnterEvent.position = lambda self: self.localPos() - QEnterEvent.globalPosition = lambda self: __QPointF(float(self.globalX()), float(self.globalY())) + QEnterEvent.globalPosition = lambda self: __QPointF( + float(self.globalX()), float(self.globalY())) QTabletEvent.position = lambda self: self.posF() QTabletEvent.globalPosition = lambda self: self.globalPosF() QHoverEvent.x = lambda self: self.pos().x() QHoverEvent.y = lambda self: self.pos().y() QHoverEvent.position = lambda self: self.posF() - # no `QHoverEvent.globalPosition`, `QHoverEvent.globalX`, nor `QHoverEvent.globalY` in the Qt5 docs + # No `QHoverEvent.globalPosition`, `QHoverEvent.globalX`, + # nor `QHoverEvent.globalY` in the Qt5 docs. QMouseEvent.position = lambda self: self.localPos() - QMouseEvent.globalPosition = lambda self: __QPointF(float(self.globalX()), float(self.globalY())) + QMouseEvent.globalPosition = lambda self: __QPointF( + float(self.globalX()), float(self.globalY())) if PYQT6 or PYSIDE6: - for _class in (QNativeGestureEvent, QEnterEvent, QTabletEvent, QHoverEvent, QMouseEvent): + for _class in (QNativeGestureEvent, QEnterEvent, QTabletEvent, QHoverEvent, + QMouseEvent): for _obsolete_function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY'): if hasattr(_class, _obsolete_function): delattr(_class, _obsolete_function) diff --git a/qtpy/tests/test_qtgui.py b/qtpy/tests/test_qtgui.py index 5bef40dc..36249415 100644 --- a/qtpy/tests/test_qtgui.py +++ b/qtpy/tests/test_qtgui.py @@ -107,7 +107,8 @@ def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None: # the rest of the functions are not actually tested for _class in ('QNativeGestureEvent', 'QEnterEvent', 'QTabletEvent'): - for _function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY', 'position', 'globalPosition'): + for _function in ('pos', 'x', 'y', 'globalPos', 'globalX', 'globalY', + 'position', 'globalPosition'): assert hasattr(getattr(QtGui, _class), _function) for _function in ('pos', 'x', 'y', 'position'): assert hasattr(QtGui.QHoverEvent, _function)