From d9add67b43cc08ed7d2cbc9e72fbd3b9ddb3a2cd Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 14 Jul 2023 13:57:49 -0500 Subject: [PATCH] qt: Mark canvas for re-draw after savefig In some cases, Qt will itself trigger a paint event after closing the file save dialog. When that happens, we need to be sure that the internal canvas is re-drawn. However, if the user is using an automatically-chosen Qt backend but saving with a different backend (such as pgf), we do not want to trigger a full draw in Qt, so just set the flag for next time. Fixes #26272 --- lib/matplotlib/backends/backend_qtagg.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/matplotlib/backends/backend_qtagg.py b/lib/matplotlib/backends/backend_qtagg.py index f89de8efba97..a9211cc01d68 100644 --- a/lib/matplotlib/backends/backend_qtagg.py +++ b/lib/matplotlib/backends/backend_qtagg.py @@ -71,6 +71,15 @@ def paintEvent(self, event): finally: painter.end() + def print_figure(self, *args, **kwargs): + super().print_figure(*args, **kwargs) + # In some cases, Qt will itself trigger a paint event after closing the file + # save dialog. When that happens, we need to be sure that the internal canvas is + # re-drawn. However, if the user is using an automatically-chosen Qt backend but + # saving with a different backend (such as pgf), we do not want to trigger a + # full draw in Qt, so just set the flag for next time. + self._draw_pending = True + @_BackendQT.export class _BackendQTAgg(_BackendQT):