Skip to content

Commit 879b7f0

Browse files
tacaswelltimhoffm
authored andcommitted
FIX: always eraseRect in Qt widget (matplotlib#13050)
Re-focusing the figure window will call the draw method. If the facecolor of the figure and axes are transparent and we do not erase the widget we are effectively compositing the figure on to its self which results in artifacts anywhere there is alpha or anti-aliasing. Closes matplotlib#13012
1 parent e7719da commit 879b7f0

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

lib/matplotlib/backends/backend_qt5.py

-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ def __init__(self, figure):
240240
self._dpi_ratio_prev = None
241241

242242
self._draw_pending = False
243-
self._erase_before_paint = False
244243
self._is_drawing = False
245244
self._draw_rect_callback = lambda painter: None
246245

@@ -491,7 +490,6 @@ def draw(self):
491490
return
492491
with cbook._setattr_cm(self, _is_drawing=True):
493492
super().draw()
494-
self._erase_before_paint = True
495493
self.update()
496494

497495
def draw_idle(self):

lib/matplotlib/backends/backend_qt5agg.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ def paintEvent(self, event):
3838

3939
painter = QtGui.QPainter(self)
4040

41-
if self._erase_before_paint:
42-
painter.eraseRect(self.rect())
43-
self._erase_before_paint = False
44-
4541
rect = event.rect()
4642
left = rect.left()
4743
top = rect.top()
@@ -55,6 +51,10 @@ def paintEvent(self, event):
5551
reg = self.copy_from_bbox(bbox)
5652
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
5753
memoryview(reg))
54+
55+
# clear the widget canvas
56+
painter.eraseRect(rect)
57+
5858
qimage = QtGui.QImage(buf, buf.shape[1], buf.shape[0],
5959
QtGui.QImage.Format_ARGB32_Premultiplied)
6060
if hasattr(qimage, 'setDevicePixelRatio'):

lib/matplotlib/backends/backend_qt5cairo.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def paintEvent(self, event):
3737
# Not available on Qt4 or some older Qt5.
3838
qimage.setDevicePixelRatio(dpi_ratio)
3939
painter = QtGui.QPainter(self)
40-
if self._erase_before_paint:
41-
painter.eraseRect(self.rect())
42-
self._erase_before_paint = False
40+
painter.eraseRect(event.rect())
4341
painter.drawImage(0, 0, qimage)
4442
self._draw_rect_callback(painter)
4543
painter.end()

0 commit comments

Comments
 (0)