Repository: pyqtgraph/pyqtgraph

Issue:
Unexpected zoom behavior when grid is activated
<!-- In the following, please describe your issue in detail! -->
<!-- If some of the sections do not apply, just remove them. -->

### Short description
If in a plot widget the grid lines are shown, then zooming behaves unexpectedly. 

### Code to reproduce
```python
import pyqtgraph as pg

app = pg.mkQApp("Zoom Example")

w = pg.PlotWidget()
w.plotItem.getAxis('left').setWidth(100)
w.showGrid(x=True, y=True)                       # this line makes the difference
x = [10, 20, 30]
y = [1, 2, 3]
w.plot(x, y, symbol='o')
w.show()

if __name__ == '__main__':
    app.exec()
```

### Expected behavior
Put the mouse pointer on the middle symbol (zoom center) and zoom in.
The zoom center should stay roughly under the mouse pointer.

### Real behavior
Logical value combinations for x and y in showGrid() produce unexpected zoom behavior.
For the below listed parameter combinations:
- (True, True) or (False, True): the expected zoom center moves to the left
- (True, False):                           the expected zoom center moves down
- (False, False):                          the zoom center stays under the mouse pointer (expected behavior)

No error happens.

### Tested environment(s)

 * PyQtGraph version: 0.12.2
 * Qt Python binding: PyQt5 5.15.4 Qt 5.15.2
 * Python version: 3.8.5
 * NumPy version: 1.21.2
 * Operating system: MacOS 11.5.2
 * Installation method: pip

### Additional context
This issue is not exhibited in pyqtgraph ver 0.12.1.
The horizontal zoom center seems to be displaced by the width of the y axis.
This issue seems to correlate with #1937 showGrid with showAxis('right', ...) causes displacement ...
Same issue is visible also under Windows10.


Discussion:
Hi @ddaann8 , thank you for the bug report, and sorry for the late reply.

This does indeed seem to be the same bug as #1937, which was traced to the `AxisItem` (which draws the grid) catching the mouse events and applying coordinate calculations that differed from what `PlotItem` would have done, if it had caught the event directly.
#2034 fixed this for the selection behavior, but did not handle the mouse events used by the zoom. However, the solution should be very similar here. If you want to have a look by yourself, we'd be happy to receive a PR!

Otherwise we will have a closer look as soon as we can get around to it!

Resolving patch:
diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py
--- a/pyqtgraph/graphicsItems/AxisItem.py
+++ b/pyqtgraph/graphicsItems/AxisItem.py
@@ -1186,8 +1186,8 @@ def wheelEvent(self, event):
             return
         # 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)
+            event.ignore()
+            return
         else:
             # pass event to linked viewbox with appropriate single axis zoom parameter
             if self.orientation in ['left', 'right']:
@@ -1202,8 +1202,8 @@ def mouseDragEvent(self, event):
             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)
+            event.ignore()
+            return
         # otherwise pass event to linked viewbox with appropriate single axis parameter
         if self.orientation in ['left', 'right']:
             return lv.mouseDragEvent(event, axis=1)


Test patch: