Skip to content

Fix ViewBox wheel event propagation#3052

Merged
j9ac9k merged 2 commits intopyqtgraph:masterfrom
tikuma-lsuhsc:fix-viewbox-wheelevent
Jul 2, 2024
Merged

Fix ViewBox wheel event propagation#3052
j9ac9k merged 2 commits intopyqtgraph:masterfrom
tikuma-lsuhsc:fix-viewbox-wheelevent

Conversation

@tikuma-lsuhsc
Copy link
Copy Markdown
Contributor

This PR makes ViewBox to ignore a wheel event if both mouseEvent flags are false. This enables graphic items to capture the wheel event when pyqtgraph's zoom/pan mechanism is turned off.

Below is a test script to demonstrate the PR. WIthout it, MyPlotItem.wheelEvent never gets called. (As far as I can tell, this event is the only one not caught by a custom PlotItem.)

import numpy as np
from PyQt6.QtCore import Qt
import pyqtgraph as pg


app = pg.mkQApp("Plotting Example")

class MyPlotItem(pg.PlotItem):

    def wheelEvent(self, event):
        print("custom wheelEvent")


p1 = MyPlotItem()


class MyWindow(pg.GraphicsLayoutWidget):

    def keyPressEvent(self, ev):

        if ev.key() == Qt.Key.Key_Space:
            # toggle zoom/pan
            if any(p1.vb.mouseEnabled()):
                print("turn off zoom/pan")
                p1.vb.setMouseEnabled(False, False)
            else:
                print("turn on  zoom/pan")
                p1.vb.setMouseEnabled(True, True)

        return super().keyPressEvent(ev)


win = MyWindow(show=True)
p1.plot(y=np.random.normal(size=100))
win.addItem(p1)

if __name__ == "__main__":
    pg.exec()

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jul 2, 2024

Thanks @tikuma-lsuhsc this LGTM! Merging.

@j9ac9k j9ac9k merged commit 43545dc into pyqtgraph:master Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants