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

Skip to content

Commit c67a944

Browse files
committed
Don't call draw() twice when Qt canvas first appears.
Right now the resizeEvent triggered from within the paintEvent will itself trigger a second paintEvent. Adding a print to draw() shows that this patch ensures that draw() only gets called once the first time the canvas appears.
1 parent df6acf9 commit c67a944

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def paintEvent(self, e):
7474
# As described in __init__ above, we need to be careful in cases with
7575
# mixed resolution displays if dpi_ratio is changing between painting
7676
# events.
77-
if (self._dpi_ratio_prev is None or
78-
self._dpi_ratio != self._dpi_ratio_prev):
77+
if self._dpi_ratio != self._dpi_ratio_prev:
7978
# We need to update the figure DPI
8079
self._update_figure_dpi()
8180
# The easiest way to resize the canvas is to emit a resizeEvent
@@ -87,6 +86,8 @@ def paintEvent(self, e):
8786
# straight away, and this causes visual delays in the changes.
8887
self.resizeEvent(event)
8988
self._dpi_ratio_prev = self._dpi_ratio
89+
# resizeEvent triggers a paintEvent itself, so we exit this one.
90+
return
9091

9192
painter = QtGui.QPainter(self)
9293

0 commit comments

Comments
 (0)