Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 333f2dc

Browse files
committed
BUG : Qt repaint workaround on windows
Added platform specific replacement of `update` with `repaint` in `FigureCanvasQtAgg.draw` for windows.
1 parent 2617d05 commit 333f2dc

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ def __init__( self, figure ):
7373
self.rect = []
7474
self.blitbox = None
7575
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
76+
# it has been reported that Qt is semi-broken in a windows
77+
# environment. If `self.draw()` uses `update` to trigger a
78+
# system-level window repaint (as is explicitly advised in the
79+
# Qt documentation) the figure responds very slowly to mouse
80+
# input. The work around is to directly use `repaint`
81+
# (against the advice of the Qt documentation). The
82+
# difference between `update` and repaint is that `update`
83+
# schedules a `repaint` for the next time the system is idle,
84+
# where as `repaint` repaints the window immediately. The
85+
# risk is if `self.draw` gets called with in another `repaint`
86+
# method there will be an infinite recursion. Thus, we only
87+
# expose windows users to this risk.
88+
if sys.platform.startswith('win'):
89+
self._priv_update = self.repaint
90+
else:
91+
self._priv_update = self.update
7692

7793
def drawRectangle( self, rect ):
7894
self.rect = rect
@@ -152,7 +168,7 @@ def draw( self ):
152168
# causes problems with code that uses the result of the
153169
# draw() to update plot elements.
154170
FigureCanvasAgg.draw(self)
155-
self.update()
171+
self._priv_update()
156172

157173
def blit(self, bbox=None):
158174
"""

0 commit comments

Comments
 (0)