@@ -38,13 +38,15 @@ def paintEvent(self, event):
38
38
39
39
painter = QtGui .QPainter (self )
40
40
41
- # get bounding box scaled to the figure
41
+ # See documentation of QRect: bottom() and right() are off by 1, so use
42
+ # left() + width() and top() + height().
42
43
rect = event .rect ()
43
- left , top = self .mouseEventCoords (rect .bottomLeft ())
44
44
width = rect .width () * self ._dpi_ratio
45
45
height = rect .height () * self ._dpi_ratio
46
- # See documentation of QRect: bottom() and right() are off by 1, so use
47
- # left() + width() and top() + height().
46
+ left , top = self .mouseEventCoords (rect .topLeft ())
47
+ # shift the "top" by the height of the image to get the
48
+ # correct corner for our coordinate system
49
+ top -= height
48
50
bbox = Bbox ([[left , top ], [left + width , top + height ]])
49
51
# create a buffer using this bounding box
50
52
reg = self .copy_from_bbox (bbox )
@@ -59,6 +61,7 @@ def paintEvent(self, event):
59
61
if hasattr (qimage , 'setDevicePixelRatio' ):
60
62
# Not available on Qt4 or some older Qt5.
61
63
qimage .setDevicePixelRatio (self ._dpi_ratio )
64
+ # set origin using original QT coordinates
62
65
origin = QtCore .QPoint (rect .left (), rect .top ())
63
66
painter .drawImage (origin , qimage )
64
67
# Adjust the buf reference count to work around a memory
0 commit comments