From c359d5fad954974cae465abd5cdda2c5d9dfaa7e Mon Sep 17 00:00:00 2001 From: 2xB <31772910+2xB@users.noreply.github.com> Date: Mon, 16 Nov 2020 23:27:40 +0100 Subject: [PATCH] Fix ViewBox axis zoom in RectMode and examples/customPlot.py (#1443) * Fix examples/customPlot.py: mouseDragEvent misses axis argument Fixes #1277 * customPlot.py: Update methodolgy to disable menu If there's an argument for this, we should use it * customPlot.py: Show how to disable axis interaction * Fix ViewBox: Moving axis in RectMode not implemented => use normal move mode Grabbing an axis in RectMode leads to the zoom rectangle being displayed in unreasonable positions. In this case, fall back to normal mode. * customPlot.py: Only disable right-click zoom for demonstration In cases where continuous zooming is not wished (e.g. in case of complicated rebinning after zooming), this might come in handy and there is no reason not to show it. Co-authored-by: 2xB <2xB@users.noreply.github.com> --- examples/customPlot.py | 10 ++++++---- pyqtgraph/graphicsItems/ViewBox/ViewBox.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/customPlot.py b/examples/customPlot.py index c5e05f91..4b9d9ee5 100644 --- a/examples/customPlot.py +++ b/examples/customPlot.py @@ -14,6 +14,7 @@ import time class CustomViewBox(pg.ViewBox): def __init__(self, *args, **kwds): + kwds['enableMenu'] = False pg.ViewBox.__init__(self, *args, **kwds) self.setMouseMode(self.RectMode) @@ -21,12 +22,13 @@ class CustomViewBox(pg.ViewBox): def mouseClickEvent(self, ev): if ev.button() == QtCore.Qt.RightButton: self.autoRange() - - def mouseDragEvent(self, ev): - if ev.button() == QtCore.Qt.RightButton: + + ## reimplement mouseDragEvent to disable continuous axis zoom + def mouseDragEvent(self, ev, axis=None): + if axis is not None and ev.button() == QtCore.Qt.RightButton: ev.ignore() else: - pg.ViewBox.mouseDragEvent(self, ev) + pg.ViewBox.mouseDragEvent(self, ev, axis=axis) app = pg.mkQApp() diff --git a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py index b08757af..7a117db0 100644 --- a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py +++ b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py @@ -1267,7 +1267,7 @@ class ViewBox(GraphicsWidget): ## Scale or translate based on mouse button if ev.button() & (QtCore.Qt.LeftButton | QtCore.Qt.MidButton): - if self.state['mouseMode'] == ViewBox.RectMode: + if self.state['mouseMode'] == ViewBox.RectMode and axis is None: if ev.isFinish(): ## This is the final move in the drag; change the view scale now #print "finish" self.rbScaleBox.hide()