Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58868ef

Browse files
committed
Don't use pixelDelta() on X11.
pixelDelta() is explicitly documented as "unreliable" and not-to-be-used on X11 (https://doc.qt.io/qt-5/qwheelevent.html#pixelDelta); locally, it reports the same value as angleDelta, but because it isn't scaled, the value is 120x too big. So add a check that forces the use of angleDelta() on X11 (see also https://doc.qt.io/qt-6/qguiapplication.html#platformName-prop).
1 parent a8dccd5 commit 58868ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/matplotlib/backends/backend_qt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,10 @@ def mouseReleaseEvent(self, event):
312312

313313
def wheelEvent(self, event):
314314
x, y = self.mouseEventCoords(self._get_position(event))
315-
# from QWheelEvent::delta doc
316-
if event.pixelDelta().x() == 0 and event.pixelDelta().y() == 0:
315+
# from QWheelEvent::pixelDelta doc: pixelDelta is sometimes not
316+
# provided (`isNull()`) and is unreliable on X11 ("xcb").
317+
if (event.pixelDelta().isNull()
318+
or QtWidgets.QApplication.instance().platformName() == "xcb"):
317319
steps = event.angleDelta().y() / 120
318320
else:
319321
steps = event.pixelDelta().y()

0 commit comments

Comments
 (0)