Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/silx/gui/plot/PlotInteraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,18 +1896,28 @@ def _onWheel(self, x: float, y: float, angle: float):
if not self.isZoomOnWheelEnabled():
return

if angle == 0:
return
plotWidget = self.parent()
if plotWidget is None:
return

# All axes are enabled if keep aspect ratio is on
enabledAxes = (
EnabledAxes()
if plotWidget.isKeepDataAspectRatio()
else self.getZoomEnabledAxes()
)
if plotWidget.isKeepDataAspectRatio():
enabledAxes = EnabledAxes()
else:
modifiers = qt.QApplication.keyboardModifiers()
shiftPressed = modifiers & qt.Qt.ShiftModifier
altPressed = modifiers & qt.Qt.AltModifier
if shiftPressed or altPressed:
enabledAxes = EnabledAxes(
xaxis=altPressed, yaxis=shiftPressed, y2axis=shiftPressed
)
else:
enabledAxes = self.getZoomEnabledAxes()
if enabledAxes.isDisabled():
return

scale = 1.1 if angle > 0 else 1.0 / 1.1

applyZoomToPlot(plotWidget, scale, (x, y), enabledAxes)
24 changes: 24 additions & 0 deletions src/silx/gui/plot/backends/BackendMatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,3 +1695,27 @@ def setGraphCursorShape(self, cursor):
else:
cursor = self._QT_CURSORS[cursor]
FigureCanvasQTAgg.setCursor(self, qt.QCursor(cursor))

def wheelEvent(self, event):
# https://github.com/qt/qtbase/blob/120883a028a59864dc7691dd1efa318bd602755d/src/plugins/platforms/xcb/qxcbwindow.cpp#L1955-L1956
# qt xcb plugin put angleDelta in x rather than in y when alt modifier is pressed.
# matplotlib/matplotlib#25671 marked as 'won't fix'
# Fix here as we want to be able to use alt modifier in silx plot.
# https://github.com/silx-kit/silx/pull/4631
if event.angleDelta().y() == 0:
event = qt.QWheelEvent(
event.position(),
event.globalPosition(),
event.pixelDelta(),
qt.QPoint(0, event.angleDelta().x()),
event.buttons(),
event.modifiers(),
event.phase(),
event.isInverted(),
event.source(),
event.pointingDevice(),
)
super().wheelEvent(event)
return

super().wheelEvent(event)
7 changes: 7 additions & 0 deletions src/silx/gui/plot/backends/BackendOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ def mouseReleaseEvent(self, event):

def wheelEvent(self, event):
delta = event.angleDelta().y()
# https://github.com/qt/qtbase/blob/120883a028a59864dc7691dd1efa318bd602755d/src/plugins/platforms/xcb/qxcbwindow.cpp#L1955-L1956
# qt xcb plugin put angleDelta in x rather than in y when alt modifier is pressed.
# matplotlib/matplotlib#25671 marked as 'won't fix'
# Fix here as we want to be able to use alt modifier in silx plot.
# https://github.com/silx-kit/silx/pull/4631
if event.angleDelta().y() == 0:
delta = event.angleDelta().x()
angleInDegrees = delta / 8.0
x, y = qt.getMouseEventPosition(event)
self._plot.onMouseWheel(x, y, angleInDegrees)
Expand Down
6 changes: 3 additions & 3 deletions src/silx/gui/plot/tools/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def __init__(self, plot: PlotWidget, parent: qt.QWidget | None = None):
self.__plotRef = weakref.ref(plot)

self.addSection("Enabled axes")
self.__xAxisAction = qt.QAction("X axis", parent=self)
self.__yAxisAction = qt.QAction("Y left axis", parent=self)
self.__y2AxisAction = qt.QAction("Y right axis", parent=self)
self.__xAxisAction = qt.QAction("X axis (Alt+Wheel)", parent=self)
self.__yAxisAction = qt.QAction("Y left axis (Shift+Wheel)", parent=self)
self.__y2AxisAction = qt.QAction("Y right axis (Shift+Wheel)", parent=self)

for action in (self.__xAxisAction, self.__yAxisAction, self.__y2AxisAction):
action.setCheckable(True)
Expand Down
Loading