Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 415d39a

Browse filesBrowse files
authored
Merge pull request #8144 from QuLogic/qt5-hidpi-fixes
Qt5: Fix event positions on HiDPI screens.
2 parents 5496805 + 419da79 commit 415d39a
Copy full SHA for 415d39a

File tree

1 file changed

+9
-2
lines changed
Filter options

1 file changed

+9
-2
lines changed

‎lib/matplotlib/backends/backend_qt5.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5.py
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,16 @@ def leaveEvent(self, event):
263263
FigureCanvasBase.leave_notify_event(self, guiEvent=event)
264264

265265
def mouseEventCoords(self, pos):
266-
x = pos.x() * self._dpi_ratio
266+
"""
267+
Calculate mouse coordinates in logical pixels.
268+
269+
Qt5 and Matplotlib use logical pixels, but the figure is scaled to
270+
physical pixels for rendering. Also, the origin is different and needs
271+
to be corrected.
272+
"""
273+
x = pos.x()
267274
# flip y so y=0 is bottom of canvas
268-
y = self.figure.bbox.height - pos.y() * self._dpi_ratio
275+
y = self.figure.bbox.height / self._dpi_ratio - pos.y()
269276
return x, y
270277

271278
def mousePressEvent(self, event):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.