Skip to content

Commit e8fa3b3

Browse files
committed
qt: Use better devicePixelRatio event to refresh scaling
With Qt 6.6, there is an event on the window that signals when the devicePixelRatio has changed. This is better than before when we had to rely on the underlying `QScreen`, which doesn't correctly refresh when a fractional scale is used. Fixes matplotlib#30218
1 parent 95db12f commit e8fa3b3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/matplotlib/backends/backend_qt.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,21 @@ def _update_screen(self, screen):
262262
screen.physicalDotsPerInchChanged.connect(self._update_pixel_ratio)
263263
screen.logicalDotsPerInchChanged.connect(self._update_pixel_ratio)
264264

265+
def eventFilter(self, source, event):
266+
if event.type() == QtCore.QEvent.Type.DevicePixelRatioChange:
267+
self._update_pixel_ratio()
268+
return super().eventFilter(source, event)
269+
265270
def showEvent(self, event):
266271
# Set up correct pixel ratio, and connect to any signal changes for it,
267272
# once the window is shown (and thus has these attributes).
268273
window = self.window().windowHandle()
269-
window.screenChanged.connect(self._update_screen)
270-
self._update_screen(window.screen())
274+
current_version = tuple(int(x) for x in QtCore.qVersion().split('.', 2)[:2])
275+
if current_version >= (6, 6):
276+
window.installEventFilter(self)
277+
else:
278+
window.screenChanged.connect(self._update_screen)
279+
self._update_screen(window.screen())
271280

272281
def set_cursor(self, cursor):
273282
# docstring inherited

0 commit comments

Comments
 (0)