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

Skip to content

Qt5Agg HiDPI support #7507

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 6 commits into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Pass HighDPI info from Qt5 to underlying Agg figure.
  • Loading branch information
QuLogic committed Dec 1, 2016
commit e5fab1c9cee67eea3c0a260bde0a0bdce82a3b8f
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ def __init__(self, figure):
w, h = self.get_width_height()
self.resize(w, h)

def get_width_height(self):
dpi_ratio = self.devicePixelRatio()
w, h = FigureCanvasBase.get_width_height(self)
return int(w / dpi_ratio), int(h / dpi_ratio)

def enterEvent(self, event):
FigureCanvasBase.enter_notify_event(self, guiEvent=event)

Expand Down Expand Up @@ -320,7 +325,7 @@ def keyReleaseEvent(self, event):
print('key release', key)

def resizeEvent(self, event):
dpi_ratio = getattr(self, '_dpi_ratio', 1)
dpi_ratio = self.devicePixelRatio()
w = event.size().width() * dpi_ratio
h = event.size().height() * dpi_ratio
if DEBUG:
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ def __init__(self, figure):
self._drawRect = None
self.blitbox = []
self._dpi_ratio = self.devicePixelRatio()
# We don't want to scale up the figure DPI more than once.
# Note, we don't handle a signal for changing DPI yet.
if not hasattr(self.figure, '_original_dpi'):
self.figure._original_dpi = self.figure.dpi
self.figure.dpi = self._dpi_ratio * self.figure._original_dpi
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)


Expand Down