Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad1534d

Browse files
committed
MNT: ensure no draws are pending in paintEvent
This prevents flickering during window resize. The issue is that the resize event triggers a paint and we have marked the figure as stale and requiring a re-draw. Sometimes the paint from the resize will process before the single-shot to trigger __draw_idle_agg and there will be a size-mismatch between the QImage and the buffer we are trying to fill it with which results in a visible flicker.
1 parent 884334d commit ad1534d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def paintEvent(self, e):
5656
In Qt, all drawing should be done inside of here when a widget is
5757
shown onscreen.
5858
"""
59-
59+
# if there is a pending draw, run it now as we need the updated render
60+
# to paint the widget
61+
if self._agg_draw_pending:
62+
self.__draw_idle_agg()
6063
# As described in __init__ above, we need to be careful in cases with
6164
# mixed resolution displays if dpi_ratio is changing between painting
6265
# events.
@@ -137,6 +140,8 @@ def draw_idle(self):
137140
QtCore.QTimer.singleShot(0, self.__draw_idle_agg)
138141

139142
def __draw_idle_agg(self, *args):
143+
if not self._agg_draw_pending:
144+
return
140145
if self.height() < 0 or self.width() < 0:
141146
self._agg_draw_pending = False
142147
return

0 commit comments

Comments
 (0)