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

Skip to content

Commit f599034

Browse files
committed
Pass HighDPI info from Qt5 to underlying Agg figure.
1 parent 02f8523 commit f599034

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ def __init__(self, figure):
243243
w, h = self.get_width_height()
244244
self.resize(w, h)
245245

246+
def get_width_height(self):
247+
dpi_ratio = self.devicePixelRatio()
248+
w, h = FigureCanvasBase.get_width_height(self)
249+
return int(w / dpi_ratio), int(h / dpi_ratio)
250+
246251
def enterEvent(self, event):
247252
FigureCanvasBase.enter_notify_event(self, guiEvent=event)
248253

@@ -320,7 +325,7 @@ def keyReleaseEvent(self, event):
320325
print('key release', key)
321326

322327
def resizeEvent(self, event):
323-
dpi_ratio = getattr(self, '_dpi_ratio', 1)
328+
dpi_ratio = self.devicePixelRatio()
324329
w = event.size().width() * dpi_ratio
325330
h = event.size().height() * dpi_ratio
326331
if DEBUG:

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ def __init__(self, figure):
229229
self._drawRect = None
230230
self.blitbox = []
231231
self._dpi_ratio = self.devicePixelRatio()
232+
# We don't want to scale up the figure DPI more than once.
233+
# Note, we don't handle a signal for changing DPI yet.
234+
if not hasattr(self.figure, '_original_dpi'):
235+
self.figure._original_dpi = self.figure.dpi
236+
self.figure.dpi = self._dpi_ratio * self.figure._original_dpi
232237
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
233238

234239

0 commit comments

Comments
 (0)