|
15 | 15 | from matplotlib import _c_internal_utils
|
16 | 16 |
|
17 | 17 | try:
|
| 18 | + from matplotlib.backends.qt_compat import QtCore # type: ignore[attr-defined] # noqa: E501, F401 |
18 | 19 | from matplotlib.backends.qt_compat import QtGui # type: ignore[attr-defined] # noqa: E501, F401
|
19 | 20 | from matplotlib.backends.qt_compat import QtWidgets # type: ignore[attr-defined]
|
20 | 21 | from matplotlib.backends.qt_editor import _formlayout
|
@@ -154,11 +155,19 @@ def test_device_pixel_ratio_change():
|
154 | 155 | def set_device_pixel_ratio(ratio):
|
155 | 156 | p.return_value = ratio
|
156 | 157 |
|
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) |
| 158 | + current_version = tuple(int(x) for x in QtCore.qVersion().split('.', 2)[:2]) |
| 159 | + if current_version >= (6, 6): |
| 160 | + # Emitting this event is simply to trigger the DPI change handler |
| 161 | + # in Matplotlib in the same manner that it would occur normally. |
| 162 | + qt_canvas.eventFilter( |
| 163 | + None, |
| 164 | + QtCore.QEvent(QtCore.QEvent.Type.DevicePixelRatioChange)) |
| 165 | + else: |
| 166 | + # The value here doesn't matter, as we can't mock the C++ QScreen |
| 167 | + # object, but can override the functional wrapper around it. |
| 168 | + # Emitting this event is simply to trigger the DPI change handler |
| 169 | + # in Matplotlib in the same manner that it would occur normally. |
| 170 | + screen.logicalDotsPerInchChanged.emit(96) |
162 | 171 |
|
163 | 172 | qt_canvas.draw()
|
164 | 173 | qt_canvas.flush_events()
|
|
0 commit comments