@@ -38,16 +38,15 @@ def paintEvent(self, event):
3838
3939 painter = QtGui .QPainter (self )
4040
41+ # get bounding box scaled to the figure
4142 rect = event .rect ()
42- left = rect .left ()
43- top = rect .top ()
44- width = rect .width ()
45- height = rect .height ()
43+ left , top = self .mouseEventCoords (rect .bottomLeft ())
44+ width = rect .width () * self ._dpi_ratio
45+ height = rect .height () * self ._dpi_ratio
4646 # See documentation of QRect: bottom() and right() are off by 1, so use
4747 # 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 ]])
48+ bbox = Bbox ([[left , top ], [left + width , top + height ]])
49+ # create a buffer using this bounding box
5150 reg = self .copy_from_bbox (bbox )
5251 buf = cbook ._unmultiplied_rgba8888_to_premultiplied_argb32 (
5352 memoryview (reg ))
@@ -60,8 +59,8 @@ def paintEvent(self, event):
6059 if hasattr (qimage , 'setDevicePixelRatio' ):
6160 # Not available on Qt4 or some older Qt5.
6261 qimage .setDevicePixelRatio (self ._dpi_ratio )
63- origin = QtCore .QPoint (left , top )
64- painter .drawImage (origin / self . _dpi_ratio , qimage )
62+ origin = QtCore .QPoint (rect . left (), rect . top () )
63+ painter .drawImage (origin , qimage )
6564 # Adjust the buf reference count to work around a memory
6665 # leak bug in QImage under PySide on Python 3.
6766 if QT_API in ('PySide' , 'PySide2' ):
0 commit comments