diff --git a/grill/views/_graph.py b/grill/views/_graph.py index 51d3af93..15f659f3 100644 --- a/grill/views/_graph.py +++ b/grill/views/_graph.py @@ -372,6 +372,9 @@ def _parallel_line(line, distance, head_offset=0): return parallel_line +_EVENT_POSITION_FUNC = QtGui.QMouseEvent if _IS_QT5 else lambda event: event.globalPosition().toPoint() + + class _GraphicsViewport(QtWidgets.QGraphicsView): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -394,7 +397,7 @@ def mousePressEvent(self, event): if event.button() == QtCore.Qt.MiddleButton: self._dragging = True QtWidgets.QApplication.setOverrideCursor(QtGui.Qt.ClosedHandCursor) - self._last_pan_pos = event.globalPosition().toPoint() + self._last_pan_pos = _EVENT_POSITION_FUNC(event) event.accept() return super().mousePressEvent(event) @@ -410,10 +413,10 @@ def mouseReleaseEvent(self, event): def mouseMoveEvent(self, event): if self._dragging and event.buttons() == QtCore.Qt.MiddleButton: # Pan the scene when middle mouse button is held down - delta = event.globalPosition().toPoint() - self._last_pan_pos + delta = _EVENT_POSITION_FUNC(event) - self._last_pan_pos self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - delta.x()) self.verticalScrollBar().setValue(self.verticalScrollBar().value() - delta.y()) - self._last_pan_pos = event.globalPosition().toPoint() + self._last_pan_pos = _EVENT_POSITION_FUNC(event) return return super().mouseMoveEvent(event) diff --git a/tests/test_views.py b/tests/test_views.py index cb517a58..a22b50d4 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -196,7 +196,7 @@ def _sub_test_scenegraph_composition(self): widget.deleteLater() - def test_layer_stack_bidirectionality(self): + def _sub_test_layer_stack_bidirectionality(self): """Confirm that bidirectionality between layer stacks completes. Bidirectionality in the composition graph is achieved by: @@ -713,7 +713,7 @@ def test_pan(self): self.assertTrue(view._dragging) # 2. Mouse move - view._last_pan_pos = middle_button_event.globalPosition().toPoint() + QtCore.QPoint(10,10) + view._last_pan_pos = _graph._EVENT_POSITION_FUNC(middle_button_event) + QtCore.QPoint(10,10) move_event = QtGui.QMouseEvent(QtCore.QEvent.MouseMove, end_position, QtCore.Qt.MiddleButton, QtCore.Qt.MiddleButton, QtCore.Qt.NoModifier) view.mouseMoveEvent(move_event) last_vertical_scroll_bar = vertical_scroll_bar.value() @@ -723,7 +723,7 @@ def test_pan(self): # 3. Release view.mouseReleaseEvent(middle_button_event) - view._last_pan_pos = middle_button_event.globalPosition().toPoint() + QtCore.QPoint(20, 20) + view._last_pan_pos = _graph._EVENT_POSITION_FUNC(middle_button_event) + QtCore.QPoint(20, 20) view.mouseMoveEvent(move_event) # Confirm no further move is performed self.assertEqual(last_vertical_scroll_bar, vertical_scroll_bar.value())