8000 FIX: qt recursive draw by tacaswell · Pull Request #9199 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: qt recursive draw #9199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,7 @@ def resize_event(self):
s = 'resize_event'
event = ResizeEvent(s, self)
self.callbacks.process(s, event)
self.draw_idle()

def close_event(self, guiEvent=None):
"""Pass a `CloseEvent` to all functions connected to ``close_event``.
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ def resizeEvent(self, event):
winch = w / dpival
hinch = h / dpival
self.figure.set_size_inches(winch, hinch, forward=False)
FigureCanvasBase.resize_event(self)
self.draw_idle()
# pass back into Qt to let it finish
QtWidgets.QWidget.resizeEvent(self, event)
# emit our resize events
FigureCanvasBase.resize_event(self)

def sizeHint(self):
w, h = self.get_width_height()
Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def paintEvent(self, e):
In Qt, all drawing should be done inside of here when a widget is
shown onscreen.
"""

# if there is a pending draw, run it now as we need the updated render
# to paint the widget
if self._agg_draw_pending:
self.__draw_idle_agg()
# As described in __init__ above, we need to be careful in cases with
# mixed resolution displays if dpi_ratio is changing between painting
# events.
Expand All @@ -72,7 +75,6 @@ def paintEvent(self, e):
# since the latter doesn't guarantee that the event will be emitted
# straight away, and this causes visual delays in the changes.
self.resizeEvent(event)
QtWidgets.QApplication.instance().processEvents()
# resizeEvent triggers a paintEvent itself, so we exit this one.
return

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

def __draw_idle_agg(self, *args):
if not self._agg_draw_pending:
return
if self.height() < 0 or self.width() < 0:
self._agg_draw_pending = False
return
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,14 @@ def set_size_inches(self, w, h=None, forward=True):

Usage ::

fig.set_size_inches(w,h) # OR
fig.set_size_inches((w,h))
fig.set_size_inches(w, h) # OR
fig.set_size_inches((w, h))

optional kwarg *forward=True* will cause the canvas size to be
automatically updated; e.g., you can resize the figure window
from the shell

ACCEPTS: a w,h tuple with w,h in inches
ACCEPTS: a w, h tuple with w, h in inches

See Also
--------
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def test_dpi_ratio_change():

qt_canvas.draw()
qApp.processEvents()
# this second processEvents is required to fully run the draw.
# On `update` we notice the DPI has changed and trigger a
# resize event to refresh, the second processEvents is
# required to process that and fully update the window sizes.
qApp.processEvents()

# The DPI and the renderer width/height change
assert fig.dpi == 240
Expand Down
0