14
14
15
15
from .backend_agg import FigureCanvasAgg
16
16
from .backend_qt5 import (
17
- QtCore , QtGui , _BackendQT5 , FigureCanvasQT , FigureManagerQT ,
17
+ QtCore , QtGui , QtWidgets , _BackendQT5 , FigureCanvasQT , FigureManagerQT ,
18
18
NavigationToolbar2QT , backend_version )
19
19
from .qt_compat import QT_API
20
20
@@ -38,15 +38,6 @@ def __init__(self, figure):
38
38
self ._bbox_queue = []
39
39
self ._drawRect = None
40
40
41
- # In cases with mixed resolution displays, we need to be careful if the
42
- # dpi_ratio changes - in this case we need to resize the canvas
43
- # accordingly. We could watch for screenChanged events from Qt, but
44
- # the issue is that we can't guarantee this will be emitted *before*
45
- # the first paintEvent for the canvas, so instead we keep track of the
46
- # dpi_ratio value here and in paintEvent we resize the canvas if
47
- # needed.
48
- self ._dpi_ratio_prev = None
49
-
50
41
def drawRectangle (self , rect ):
51
42
if rect is not None :
52
43
self ._drawRect = [pt / self ._dpi_ratio for pt in rect ]
@@ -66,18 +57,13 @@ def paintEvent(self, e):
66
57
shown onscreen.
67
58
"""
68
59
69
- # if the canvas does not have a renderer, then give up and wait for
70
- # FigureCanvasAgg.draw(self) to be called
71
- if not hasattr (self , 'renderer' ):
72
- return
73
-
74
60
# As described in __init__ above, we need to be careful in cases with
75
61
# mixed resolution displays if dpi_ratio is changing between painting
76
62
# events.
77
- if (self ._dpi_ratio_prev is None or
78
- self ._dpi_ratio != self ._dpi_ratio_prev ):
63
+ if self ._dpi_ratio != self ._dpi_ratio_prev :
79
64
# We need to update the figure DPI
80
65
self ._update_figure_dpi ()
66
+ self ._dpi_ratio_prev = self ._dpi_ratio
81
67
# The easiest way to resize the canvas is to emit a resizeEvent
82
68
# since we implement all the logic for resizing the canvas for
83
69
# that event.
@@ -86,7 +72,14 @@ def paintEvent(self, e):
86
72
# since the latter doesn't guarantee that the event will be emitted
87
73
# straight away, and this causes visual delays in the changes.
88
74
self .resizeEvent (event )
89
- self ._dpi_ratio_prev = self ._dpi_ratio
75
+ QtWidgets .QApplication .instance ().processEvents ()
76
+ # resizeEvent triggers a paintEvent itself, so we exit this one.
77
+ return
78
+
79
+ # if the canvas does not have a renderer, then give up and wait for
80
+ # FigureCanvasAgg.draw(self) to be called
81
+ if not hasattr (self , 'renderer' ):
82
+ return
90
83
91
84
painter = QtGui .QPainter (self )
92
85
0 commit comments