15
15
16
16
class FigureCanvasQTAgg (FigureCanvasAgg , FigureCanvasQT ):
17
17
18
- def __init__ (self , figure ):
19
- super ().__init__ (figure = figure )
20
- self ._bbox_queue = []
21
-
22
- def paintEvent (self , e ):
18
+ def paintEvent (self , event ):
23
19
"""Copy the image from the Agg canvas to the qt.drawable.
24
20
25
21
In Qt, all drawing should be done inside of here when a widget is
@@ -37,29 +33,31 @@ def paintEvent(self, e):
37
33
38
34
painter = QtGui .QPainter (self )
39
35
40
- if self ._bbox_queue :
41
- bbox_queue = self ._bbox_queue
42
- else :
36
+ if self ._erase_before_paint :
43
37
painter .eraseRect (self .rect ())
44
- bbox_queue = [
45
- Bbox ([[0 , 0 ], [self .renderer .width , self .renderer .height ]])]
46
- self ._bbox_queue = []
47
- for bbox in bbox_queue :
48
- l , b , r , t = map (int , bbox .extents )
49
- w = r - l
50
- h = t - b
51
- reg = self .copy_from_bbox (bbox )
52
- buf = reg .to_string_argb ()
53
- qimage = QtGui .QImage (buf , w , h , QtGui .QImage .Format_ARGB32 )
54
- # Adjust the buf reference count to work around a memory leak bug
55
- # in QImage under PySide on Python 3.
56
- if QT_API == 'PySide' :
57
- ctypes .c_long .from_address (id (buf )).value = 1
58
- if hasattr (qimage , 'setDevicePixelRatio' ):
59
- # Not available on Qt4 or some older Qt5.
60
- qimage .setDevicePixelRatio (self ._dpi_ratio )
61
- origin = QtCore .QPoint (l , self .renderer .height - t )
62
- painter .drawImage (origin / self ._dpi_ratio , qimage )
38
+ self ._erase_before_paint = False
39
+
40
+ rect = event .rect ()
41
+ left = rect .left ()
42
+ top = rect .top ()
43
+ width = rect .width ()
44
+ height = rect .height ()
45
+ # See documentation of QRect: bottom() and right() are off by 1, so use
46
+ # left() + width() and top() + height().
47
+ bbox = Bbox ([[left , self .renderer .height - (top + height )],
48
+ [left + width , self .renderer .height - top ]])
49
+ reg = self .copy_from_bbox (bbox )
50
+ buf = reg .to_string_argb ()
51
+ qimage = QtGui .QImage (buf , width , height , QtGui .QImage .Format_ARGB32 )
52
+ if hasattr (qimage , 'setDevicePixelRatio' ):
53
+ # Not available on Qt4 or some older Qt5.
54
+ qimage .setDevicePixelRatio (self ._dpi_ratio )
55
+ origin = QtCore .QPoint (left , top )
56
+ painter .drawImage (origin / self ._dpi_ratio , qimage )
57
+ # Adjust the buf reference count to work around a memory
58
+ # leak bug in QImage under PySide on Python 3.
59
+ if QT_API == 'PySide' :
60
+ ctypes .c_long .from_address (id (buf )).value = 1
63
61
64
62
self ._draw_rect_callback (painter )
65
63
@@ -73,8 +71,6 @@ def blit(self, bbox=None):
73
71
if bbox is None and self .figure :
74
72
bbox = self .figure .bbox
75
73
76
- self ._bbox_queue .append (bbox )
77
-
78
74
# repaint uses logical pixels, not physical pixels like the renderer.
79
75
l , b , w , h = [pt / self ._dpi_ratio for pt in bbox .bounds ]
80
76
t = b + h
0 commit comments