@@ -137,7 +137,7 @@ def on_key_press(event):
137137
138138
139139@pytest .mark .backend ('QtAgg' , skip_on_importerror = True )
140- def test_device_pixel_ratio_change ():
140+ def test_device_pixel_ratio_change (qt_core ):
141141 """
142142 Make sure that if the pixel ratio changes, the figure dpi changes but the
143143 widget remains the same logical size.
@@ -154,11 +154,19 @@ def test_device_pixel_ratio_change():
154154 def set_device_pixel_ratio (ratio ):
155155 p .return_value = ratio
156156
157- # The value here doesn't matter, as we can't mock the C++ QScreen
158- # object, but can override the functional wrapper around it.
159- # Emitting this event is simply to trigger the DPI change handler
160- # in Matplotlib in the same manner that it would occur normally.
161- screen .logicalDotsPerInchChanged .emit (96 )
157+ window = qt_canvas .window ().windowHandle ()
158+ current_version = tuple (
159+ int (x ) for x in qt_core .qVersion ().split ('.' , 2 )[:2 ])
160+ if current_version >= (6 , 6 ):
161+ qt_core .QCoreApplication .sendEvent (
162+ window ,
163+ qt_core .QEvent (qt_core .QEvent .Type .DevicePixelRatioChange ))
164+ else :
165+ # The value here doesn't matter, as we can't mock the C++ QScreen
166+ # object, but can override the functional wrapper around it.
167+ # Emitting this event is simply to trigger the DPI change handler
168+ # in Matplotlib in the same manner that it would occur normally.
169+ window .screen ().logicalDotsPerInchChanged .emit (96 )
162170
163171 qt_canvas .draw ()
164172 qt_canvas .flush_events ()
@@ -168,7 +176,6 @@ def set_device_pixel_ratio(ratio):
168176
169177 qt_canvas .manager .show ()
170178 size = qt_canvas .size ()
171- screen = qt_canvas .window ().windowHandle ().screen ()
172179 set_device_pixel_ratio (3 )
173180
174181 # The DPI and the renderer width/height change
0 commit comments