@@ -137,7 +137,7 @@ def on_key_press(event):
137
137
138
138
139
139
@pytest .mark .backend ('QtAgg' , skip_on_importerror = True )
140
- def test_device_pixel_ratio_change ():
140
+ def test_device_pixel_ratio_change (qt_core ):
141
141
"""
142
142
Make sure that if the pixel ratio changes, the figure dpi changes but the
143
143
widget remains the same logical size.
@@ -154,11 +154,19 @@ def test_device_pixel_ratio_change():
154
154
def set_device_pixel_ratio (ratio ):
155
155
p .return_value = ratio
156
156
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 )
162
170
163
171
qt_canvas .draw ()
164
172
qt_canvas .flush_events ()
@@ -168,7 +176,6 @@ def set_device_pixel_ratio(ratio):
168
176
169
177
qt_canvas .manager .show ()
170
178
size = qt_canvas .size ()
171
- screen = qt_canvas .window ().windowHandle ().screen ()
172
179
set_device_pixel_ratio (3 )
173
180
174
181
# The DPI and the renderer width/height change
0 commit comments