@@ -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