Skip to content

Commit f0dffc7

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.
1 parent 95db12f commit f0dffc7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/matplotlib/backends/backend_qt.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,22 @@ 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 source is self.window().windowHandle():
267+
if event.type() == QtCore.QEvent.Type.DevicePixelRatioChange:
268+
self._update_pixel_ratio()
269+
return super().eventFilter(source, event)
270+
265271
def showEvent(self, event):
266272
# Set up correct pixel ratio, and connect to any signal changes for it,
267273
# once the window is shown (and thus has these attributes).
268274
window = self.window().windowHandle()
269-
window.screenChanged.connect(self._update_screen)
270-
self._update_screen(window.screen())
275+
current_version = tuple(int(x) for x in QtCore.qVersion().split('.', 2)[:2])
276+
if current_version >= (6, 6):
277+
window.installEventFilter(self)
278+
else:
279+
window.screenChanged.connect(self._update_screen)
280+
self._update_screen(window.screen())
271281

272282
def set_cursor(self, cursor):
273283
# docstring inherited

0 commit comments

Comments
 (0)