diff --git a/lib/matplotlib/backends/backend_qt4agg.py b/lib/matplotlib/backends/backend_qt4agg.py index 39b2793831e7..b6830573c983 100644 --- a/lib/matplotlib/backends/backend_qt4agg.py +++ b/lib/matplotlib/backends/backend_qt4agg.py @@ -73,22 +73,6 @@ def __init__(self, figure): self._drawRect = None self.blitbox = None self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) - # it has been reported that Qt is semi-broken in a windows - # environment. If `self.draw()` uses `update` to trigger a - # system-level window repaint (as is explicitly advised in the - # Qt documentation) the figure responds very slowly to mouse - # input. The work around is to directly use `repaint` - # (against the advice of the Qt documentation). The - # difference between `update` and repaint is that `update` - # schedules a `repaint` for the next time the system is idle, - # where as `repaint` repaints the window immediately. The - # risk is if `self.draw` gets called with in another `repaint` - # method there will be an infinite recursion. Thus, we only - # expose windows users to this risk. - if sys.platform.startswith('win'): - self._priv_update = self.repaint - else: - self._priv_update = self.update FigureCanvas = FigureCanvasQTAgg diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index c39d406e0d28..baf76593cc57 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -334,8 +334,7 @@ def resizeEvent(self, event): hinch = h / dpival self.figure.set_size_inches(winch, hinch) FigureCanvasBase.resize_event(self) - self.draw() - self.update() + self.draw_idle() QtWidgets.QWidget.resizeEvent(self, event) def sizeHint(self): @@ -417,17 +416,7 @@ def stop_event_loop(self): stop_event_loop.__doc__ = FigureCanvasBase.stop_event_loop_default.__doc__ def draw_idle(self): - 'update drawing area only if idle' - d = self._idle - self._idle = False - - def idle_draw(*args): - try: - self.draw() - finally: - self._idle = True - if d: - QtCore.QTimer.singleShot(0, idle_draw) + self.update() class MainWindow(QtWidgets.QMainWindow): @@ -666,7 +655,7 @@ def zoom(self, *args): self._update_buttons_checked() def dynamic_update(self): - self.canvas.draw() + self.canvas.draw_idle() def set_message(self, s): self.message.emit(s) diff --git a/lib/matplotlib/backends/backend_qt5agg.py b/lib/matplotlib/backends/backend_qt5agg.py index a97c1cf5ab86..2ab431bfccaa 100644 --- a/lib/matplotlib/backends/backend_qt5agg.py +++ b/lib/matplotlib/backends/backend_qt5agg.py @@ -63,7 +63,7 @@ class FigureCanvasQTAggBase(object): def drawRectangle(self, rect): self._drawRect = rect - self.repaint() + self.draw_idle() def paintEvent(self, e): """ @@ -71,6 +71,7 @@ def paintEvent(self, e): In Qt, all drawing should be done inside of here when a widget is shown onscreen. """ + FigureCanvasAgg.draw(self) # FigureCanvasQT.paintEvent(self, e) if DEBUG: @@ -146,7 +147,7 @@ def draw(self): # causes problems with code that uses the result of the # draw() to update plot elements. FigureCanvasAgg.draw(self) - self._priv_update() + self.update() def blit(self, bbox=None): """ @@ -183,22 +184,6 @@ def __init__(self, figure): self._drawRect = None self.blitbox = None self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) - # it has been reported that Qt is semi-broken in a windows - # environment. If `self.draw()` uses `update` to trigger a - # system-level window repaint (as is explicitly advised in the - # Qt documentation) the figure responds very slowly to mouse - # input. The work around is to directly use `repaint` - # (against the advice of the Qt documentation). The - # difference between `update` and repaint is that `update` - # schedules a `repaint` for the next time the system is idle, - # where as `repaint` repaints the window immediately. The - # risk is if `self.draw` gets called with in another `repaint` - # method there will be an infinite recursion. Thus, we only - # expose windows users to this risk. - if sys.platform.startswith('win'): - self._priv_update = self.repaint - else: - self._priv_update = self.update FigureCanvas = FigureCanvasQTAgg