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

Sign up
Appearance settings
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit b4f88e8

Browse files
Merge pull request matplotlib#23729 from anthepro/resizeeventfix
Use cleaner recursion check in PyQt FigureCanvas' resizeEvent.
2 parents 36f2745 + 0ee28e0 commit b4f88e8

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

‎lib/matplotlib/backends/backend_qt.py‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def __init__(self, figure=None):
211211
self._draw_pending = False
212212
self._is_drawing = False
213213
self._draw_rect_callback = lambda painter: None
214+
self._in_resize_event = False
214215

215216
self.setAttribute(
216217
_enum("QtCore.Qt.WidgetAttribute").WA_OpaquePaintEvent)
@@ -333,21 +334,23 @@ def keyReleaseEvent(self, event):
333334
guiEvent=event)._process()
334335

335336
def resizeEvent(self, event):
336-
frame = sys._getframe()
337-
# Prevent PyQt6 recursion, but sometimes frame.f_back is None
338-
if frame.f_code is getattr(frame.f_back, 'f_code', None):
337+
if self._in_resize_event: # Prevent PyQt6 recursion
339338
return
340-
w = event.size().width() * self.device_pixel_ratio
341-
h = event.size().height() * self.device_pixel_ratio
342-
dpival = self.figure.dpi
343-
winch = w / dpival
344-
hinch = h / dpival
345-
self.figure.set_size_inches(winch, hinch, forward=False)
346-
# pass back into Qt to let it finish
347-
QtWidgets.QWidget.resizeEvent(self, event)
348-
# emit our resize events
349-
ResizeEvent("resize_event", self)._process()
350-
self.draw_idle()
339+
self._in_resize_event = True
340+
try:
341+
w = event.size().width() * self.device_pixel_ratio
342+
h = event.size().height() * self.device_pixel_ratio
343+
dpival = self.figure.dpi
344+
winch = w / dpival
345+
hinch = h / dpival
346+
self.figure.set_size_inches(winch, hinch, forward=False)
347+
# pass back into Qt to let it finish
348+
QtWidgets.QWidget.resizeEvent(self, event)
349+
# emit our resize events
350+
ResizeEvent("resize_event", self)._process()
351+
self.draw_idle()
352+
finally:
353+
self._in_resize_event = False
351354

352355
def sizeHint(self):
353356
w, h = self.get_width_height()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /