From 775f1d629c9f31404f805b3a54bce705cce652db Mon Sep 17 00:00:00 2001 From: Nils Nemitz Date: Wed, 23 Jun 2021 08:17:39 +0900 Subject: [PATCH] Separate out mouse events stolen by AxisItem (#1845) * separate out mouse events on main plot area * work in scenepositions so that detection also works in a layout * added comments/remove debug statements --- pyqtgraph/graphicsItems/AxisItem.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py index e4f37fc5..97baebc4 100644 --- a/pyqtgraph/graphicsItems/AxisItem.py +++ b/pyqtgraph/graphicsItems/AxisItem.py @@ -1151,7 +1151,7 @@ class AxisItem(GraphicsWidget): pen, p1, p2 = axisSpec p.setPen(pen) p.drawLine(p1, p2) - p.translate(0.5,0) ## resolves some damn pixel ambiguity + # p.translate(0.5,0) ## resolves some damn pixel ambiguity ## draw ticks for pen, p1, p2 in tickSpecs: @@ -1184,20 +1184,31 @@ class AxisItem(GraphicsWidget): else: self._updateHeight() - def wheelEvent(self, ev): + def wheelEvent(self, event): lv = self.linkedView() if lv is None: return - if self.orientation in ['left', 'right']: - lv.wheelEvent(ev, axis=1) + # Did the event occur inside the linked ViewBox (and not over the axis iteself)? + if lv.sceneBoundingRect().contains(event.scenePos()): + # pass event to linked ViewBox without marking it as single axis zoom + lv.wheelEvent(event) else: - lv.wheelEvent(ev, axis=0) - ev.accept() + # pass event to linked viewbox with appropriate single axis zoom parameter + if self.orientation in ['left', 'right']: + lv.wheelEvent(event, axis=1) + else: + lv.wheelEvent(event, axis=0) + event.accept() def mouseDragEvent(self, event): lv = self.linkedView() if lv is None: return + # Did the mouse down event occur inside the linked ViewBox (and not the axis)? + if lv.sceneBoundingRect().contains(event.buttonDownScenePos()): + # pass event to linked ViewBox without marking it as single axis pan + return lv.mouseDragEvent(event) + # otherwise pass event to linked viewbox with appropriate single axis parameter if self.orientation in ['left', 'right']: return lv.mouseDragEvent(event, axis=1) else: