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

Skip to content

Commit 4f809f4

Browse files
committed
Fix blitting with HighDPI Qt5.
The renderer and backing QPixmap use doubled (or whatever) pixels, but the painter continues to use logical pixels for positioning.
1 parent c1ca736 commit 4f809f4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ def paintEvent(self, e):
149149
if QT_API == 'PySide' and six.PY3:
150150
ctypes.c_long.from_address(id(stringBuffer)).value = 1
151151

152+
origin = QtCore.QPoint(l, self.renderer.height - t)
152153
pixmap = QtGui.QPixmap.fromImage(qImage)
153-
p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap)
154+
p.drawPixmap(origin / self._dpi_ratio, pixmap)
154155

155156
# draw the zoom rectangle to the QPainter
156157
if self._drawRect is not None:
@@ -207,9 +208,11 @@ def blit(self, bbox=None):
207208
bbox = self.figure.bbox
208209

209210
self.blitbox.append(bbox)
210-
l, b, w, h = bbox.bounds
211+
212+
# repaint uses logical pixels, not physical pixels like the renderer.
213+
l, b, w, h = [pt / self._dpi_ratio for pt in bbox.bounds]
211214
t = b + h
212-
self.repaint(l, self.renderer.height-t, w, h)
215+
self.repaint(l, self.renderer.height / self._dpi_ratio - t, w, h)
213216

214217
def print_figure(self, *args, **kwargs):
215218
FigureCanvasAgg.print_figure(self, *args, **kwargs)

0 commit comments

Comments
 (0)