Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9856ec2

Browse filesBrowse files
authored
Merge pull request #14456 from pshriwise/bbox_fix_qt5
PyQT5 Backend Partial Redraw Fix
2 parents db92807 + 13237c2 commit 9856ec2
Copy full SHA for 9856ec2

File tree

Expand file treeCollapse file tree

1 file changed

+16
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-10
lines changed
Open diff view settings
Collapse file

‎lib/matplotlib/backends/backend_qt5agg.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5agg.py
+16-10Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.