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

Skip to content

Qt5: Fix event positions on HiDPI screens. #8144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2017
Merged
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
11 changes: 9 additions & 2 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,16 @@ def leaveEvent(self, event):
FigureCanvasBase.leave_notify_event(self, guiEvent=event)

def mouseEventCoords(self, pos):
x = pos.x() * self._dpi_ratio
"""
Calculate mouse coordinates in logical pixels.

Qt5 and Matplotlib use logical pixels, but the figure is scaled to
physical pixels for rendering. Also, the origin is different and needs
to be corrected.
"""
x = pos.x()
# flip y so y=0 is bottom of canvas
y = self.figure.bbox.height - pos.y() * self._dpi_ratio
y = self.figure.bbox.height / self._dpi_ratio - pos.y()
return x, y

def mousePressEvent(self, event):
Expand Down