8000 Merge pull request #9199 from tacaswell/fix_qt_transient · matplotlib/matplotlib@c3d57bc · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c3d57bc

Browse files
authored
Merge pull request #9199 from tacaswell/fix_qt_transient
FIX: qt recursive draw
2 parents 6889c6d + 04ee64d commit c3d57bc

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ def resize_event(self):
18451845
s = 'resize_event'
18461846
event = ResizeEvent(s, self)
18471847
self.callbacks.process(s, event)
1848+
self.draw_idle()
18481849

18491850
def close_event(self, guiEvent=None):
18501851
"""Pass a `CloseEvent` to all functions connected to ``close_event``.

lib/matplotlib/backends/backend_qt5.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,10 @@ def resizeEvent(self, event):
359359
winch = w / dpival
360360
hinch = h / dpival
361361
self.figure.set_size_inches(winch, hinch, forward=False)
362-
FigureCanvasBase.resize_event(self)
363-
self.draw_idle()
362+
# pass back into Qt to let it finish
364363
QtWidgets.QWidget.resizeEvent(self, event)
364+
# emit our resize events
365+
FigureCanvasBase.resize_event(self)
365366

366367
def sizeHint(self):
367368
w, h = self.get_width_height()

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 6 additions & 2 deletions
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.
@@ -72,7 +75,6 @@ def paintEvent(self, e):
7275
# since the latter doesn't guarantee that the event will be emitted
7376
# straight away, and this causes visual delays in the changes.
7477
self.resizeEvent(event)
75-
QtWidgets.QApplication.instance().processEvents()
7678
# resizeEvent triggers a paintEvent itself, so we exit this one.
7779
return
7880

@@ -138,6 +140,8 @@ def draw_idle(self):
138140
QtCore.QTimer.singleShot(0, self.__draw_idle_agg)
139141

140142
def __draw_idle_agg(self, *args):
143+
if not self._agg_draw_pending:
144+
return
141145
if self.height() < 0 or self.width() < 0:
142146
self._agg_draw_pending = False
143147
return

lib/matplotlib/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,14 @@ def set_size_inches(self, w, h=None, forward=True):
708708
709709
Usage ::
710710
711-
fig.set_size_inches(w,h) # OR
712-
fig.set_size_inches((w,h))
711+
fig.set_size_inches(w, h) # OR
712+
fig.set_size_inches((w, h))
713713
714714
optional kwarg *forward=True* will cause the canvas size to be
715715
automatically updated; e.g., you can resize the figure window
716716
from the shell
717717
718-
ACCEPTS: a w,h tuple with w,h in inches
718+
ACCEPTS: a w, h tuple with w, h in inches
719719
720720
See Also
721721
--------

lib/matplotlib/tests/test_backend_qt5.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ def test_dpi_ratio_change():
145145

146146
qt_canvas.draw()
147147
qApp.processEvents()
148+
# this second processEvents is required to fully run the draw.
149+
# On `update` we notice the DPI has changed and trigger a
150+
# resize event to refresh, the second processEvents is
151+
# required to process that and fully update the window sizes.
152+
qApp.processEvents()
148153

149154
# The DPI and the renderer width/height change
150155
assert fig.dpi == 240

0 commit comments

Comments
 (0)
0