@@ -169,45 +169,30 @@ def set_device_pixel_ratio(ratio):
169169 assert qt_canvas .device_pixel_ratio == ratio
170170
171171 qt_canvas .manager .show ()
172+ qt_canvas .draw ()
173+ qt_canvas .flush_events ()
172174 size = qt_canvas .size ()
173- set_device_pixel_ratio (3 )
174-
175- # The DPI and the renderer width/height change
176- assert fig .dpi == 360
177- assert qt_canvas .renderer .width == 1800
178- assert qt_canvas .renderer .height == 720
179-
180- # The actual widget size and figure logical size don't change.
181- assert size .width () == 600
182- assert size .height () == 240
183- assert qt_canvas .get_width_height () == (600 , 240 )
184- assert (fig .get_size_inches () == (5 , 2 )).all ()
185-
186- set_device_pixel_ratio (2 )
187-
188- # The DPI and the renderer width/height change
189- assert fig .dpi == 240
190- assert qt_canvas .renderer .width == 1200
191- assert qt_canvas .renderer .height == 480
192-
193- # The actual widget size and figure logical size don't change.
194- assert size .width () == 600
195- assert size .height () == 240
196- assert qt_canvas .get_width_height () == (600 , 240 )
197- assert (fig .get_size_inches () == (5 , 2 )).all ()
198-
199- set_device_pixel_ratio (1.5 )
200-
201- # The DPI and the renderer width/height change
202- assert fig .dpi == 180
203- assert qt_canvas .renderer .width == 900
204- assert qt_canvas .renderer .height == 360
205-
206- # The actual widget size and figure logical size don't change.
207- assert size .width () == 600
208- assert size .height () == 240
209- assert qt_canvas .get_width_height () == (600 , 240 )
210- assert (fig .get_size_inches () == (5 , 2 )).all ()
175+
176+ options = [
177+ (None , 360 , 1800 , 720 ), # Use ratio at startup time.
178+ (3 , 360 , 1800 , 720 ), # Change to same ratio.
179+ (2 , 240 , 1200 , 480 ), # Change to different ratio.
180+ (1.5 , 180 , 900 , 360 ), # Fractional ratio.
181+ ]
182+ for ratio , dpi , width , height in options :
183+ if ratio is not None :
184+ set_device_pixel_ratio (ratio )
185+
186+ # The DPI and the renderer width/height change
187+ assert fig .dpi == dpi
188+ assert qt_canvas .renderer .width == width
189+ assert qt_canvas .renderer .height == height
190+
191+ # The actual widget size and figure logical size don't change.
192+ assert size .width () == 600
193+ assert size .height () == 240
194+ assert qt_canvas .get_width_height () == (600 , 240 )
195+ assert (fig .get_size_inches () == (5 , 2 )).all ()
211196
212197
213198@pytest .mark .backend ('QtAgg' , skip_on_importerror = True )
0 commit comments