@@ -43,7 +43,8 @@ def __init__(self, figure):
4343 # accordingly. We could watch for screenChanged events from Qt, but
4444 # the issue is that we can't guarantee this will be emitted *before*
4545 # 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 needed.
46+ # dpi_ratio value here and in paintEvent we resize the canvas if
47+ # needed.
4748 self ._dpi_ratio_prev = None
4849
4950 def drawRectangle (self , rect ):
@@ -68,9 +69,10 @@ def paintEvent(self, e):
6869 # As described in __init__ above, we need to be careful in cases with
6970 # mixed resolution displays if dpi_ratio is changing between painting
7071 # events.
71- if self ._dpi_ratio_prev is None :
72- self ._dpi_ratio_prev = self ._dpi_ratio
73- elif self ._dpi_ratio != self ._dpi_ratio_prev :
72+ if (self ._dpi_ratio_prev is None or
73+ self ._dpi_ratio != self ._dpi_ratio_prev ):
74+ # We need to update the figure DPI
75+ self ._update_figure_dpi ()
7476 # The easiest way to resize the canvas is to emit a resizeEvent
7577 # since we implement all the logic for resizing the canvas for
7678 # that event.
@@ -196,6 +198,10 @@ def __init__(self, figure):
196198 self .figure ._original_dpi = self .figure .dpi
197199 self .figure .dpi = self ._dpi_ratio * self .figure ._original_dpi
198200
201+ def _update_figure_dpi (self ):
202+ dpi = self ._dpi_ratio * self .figure ._original_dpi
203+ self .figure ._set_dpi (dpi , forward = False )
204+
199205
200206@_BackendQT5 .export
201207class _BackendQT5Agg (_BackendQT5 ):
0 commit comments