From f4948aae677214a681a027b95d9ca0b1fcc06835 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 25 Dec 2018 13:20:41 -0500 Subject: [PATCH] FIX: always eraseRect in Qt widget 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 #13012 --- lib/matplotlib/backends/backend_qt5.py | 2 -- lib/matplotlib/backends/backend_qt5agg.py | 8 ++++---- lib/matplotlib/backends/backend_qt5cairo.py | 4 +--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 4c7c0194160d..79537c413939 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -240,7 +240,6 @@ def __init__(self, figure): self._dpi_ratio_prev = None self._draw_pending = False - self._erase_before_paint = False self._is_drawing = False self._draw_rect_callback = lambda painter: None @@ -491,7 +490,6 @@ def draw(self): return with cbook._setattr_cm(self, _is_drawing=True): super().draw() - self._erase_before_paint = True self.update() def draw_idle(self): diff --git a/lib/matplotlib/backends/backend_qt5agg.py b/lib/matplotlib/backends/backend_qt5agg.py index ae37afe0bdbb..eadb0138fa5c 100644 --- a/lib/matplotlib/backends/backend_qt5agg.py +++ b/lib/matplotlib/backends/backend_qt5agg.py @@ -38,10 +38,6 @@ def paintEvent(self, event): painter = QtGui.QPainter(self) - if self._erase_before_paint: - painter.eraseRect(self.rect()) - self._erase_before_paint = False - rect = event.rect() left = rect.left() top = rect.top() @@ -55,6 +51,10 @@ def paintEvent(self, event): reg = self.copy_from_bbox(bbox) buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32( memoryview(reg)) + + # clear the widget canvas + painter.eraseRect(rect) + qimage = QtGui.QImage(buf, buf.shape[1], buf.shape[0], QtGui.QImage.Format_ARGB32_Premultiplied) if hasattr(qimage, 'setDevicePixelRatio'): diff --git a/lib/matplotlib/backends/backend_qt5cairo.py b/lib/matplotlib/backends/backend_qt5cairo.py index bea4f6069c33..5a38a80864be 100644 --- a/lib/matplotlib/backends/backend_qt5cairo.py +++ b/lib/matplotlib/backends/backend_qt5cairo.py @@ -37,9 +37,7 @@ def paintEvent(self, event): # Not available on Qt4 or some older Qt5. qimage.setDevicePixelRatio(dpi_ratio) painter = QtGui.QPainter(self) - if self._erase_before_paint: - painter.eraseRect(self.rect()) - self._erase_before_paint = False + painter.eraseRect(event.rect()) painter.drawImage(0, 0, qimage) self._draw_rect_callback(painter) painter.end()