@@ -38,16 +38,21 @@ def paintEvent(self, event):
38
38
39
39
painter = QtGui .QPainter (self )
40
40
41
- rect = event .rect ()
42
- left = rect .left ()
43
- top = rect .top ()
44
- width = rect .width ()
45
- height = rect .height ()
46
41
# See documentation of QRect: bottom() and right() are off by 1, so use
47
42
# 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 ]])
51
56
reg = self .copy_from_bbox (bbox )
52
57
buf = cbook ._unmultiplied_rgba8888_to_premultiplied_argb32 (
53
58
memoryview (reg ))
@@ -60,8 +65,9 @@ def paintEvent(self, event):
60
65
if hasattr (qimage , 'setDevicePixelRatio' ):
61
66
# Not available on Qt4 or some older Qt5.
62
67
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 )
65
71
# Adjust the buf reference count to work around a memory
66
72
# leak bug in QImage under PySide on Python 3.
67
73
if QT_API in ('PySide' , 'PySide2' ):
0 commit comments