8000 Merge pull request #15153 from meeseeksmachine/auto-backport-of-pr-14… · matplotlib/matplotlib@f588373 · GitHub
[go: up one dir, main page]

Skip to content

Commit f588373

Browse files
authored
Merge pull request #15153 from meeseeksmachine/auto-backport-of-pr-14456-on-v3.1.x
Backport PR #14456 on branch v3.1.x (PyQT5 Backend Partial Redraw Fix)
2 parents 6caf7d8 + 9cb2251 commit f588373

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,21 @@ def paintEvent(self, event):
3838

3939
painter = QtGui.QPainter(self)
4040

41-
rect = event.rect()
42-
left = rect.left()
43-
top = rect.top()
44-
width = rect.width()
45-
height = rect.height()
4641
# See documentation of QRect: bottom() and right() are off by 1, so use
4742
# left() + width() and top() + height().
48-
bbox = Bbox(
49-
[[left, self.renderer.height - (top + height * self._dpi_ratio)],
50-
[left + width * self._dpi_ratio, self.renderer.height - top]])
43+
rect = event.rect()
44+
# scale rect dimensions using the screen dpi ratio to get
45+
# correct values for the Figure coordinates (rather than QT5's coords)
46+
width = rect.width() * self._dpi_ratio
47+
height = rect.height() * self._dpi_ratio
48+
left, top = self.mouseEventCoords(rect.topLeft())
49+
# shift the "top" by the height of the image to get the
50+
# correct corner for our coordinate system
51+
bottom = top - height
52+
# same with the right side of the image
53+
right = left + width
54+
# create a buffer using the image bounding box
55+
bbox = Bbox([[left, bottom], [right, top]])
5156
reg = self.copy_from_bbox(bbox)
5257
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
5358
memoryview(reg))
@@ -60,8 +65,9 @@ def paintEvent(self, event):
6065
if hasattr(qimage, 'setDevicePixelRatio'):
6166
# Not available on Qt4 or some older Qt5.
6267
qimage.setDevicePixelRatio(self._dpi_ratio)
63-
origin = QtCore.QPoint(left, top)
64-
painter.drawImage(origin / self._dpi_ratio, qimage)
68+
# set origin using original QT coordinates
69+
origin = QtCore.QPoint(rect.left(), rect.top())
70+
painter.drawImage(origin, qimage)
6571
# Adjust the buf reference count to work around a memory
6672
# leak bug in QImage under PySide on Python 3.
6773
if QT_API in ('PySide', 'PySide2'):

0 commit comments

Comments
 (0)
0