[PyQt] Heads up about window corruption on X11 when HiDPI scaling enabled in Qt 5
damonlynch at gmail.com
Thu Apr 16 18:27:50 BST 2020
This is a follow-up to my message of six days ago, in which the goal avoid
cases where enabling Qt scaling support as default behavior will cause bad
window corruption on some systems. The specific goal is to only enable
scaling when a monitor on the system is actually scaled. The problem is
that Gtk and Qt desktops approach monitor scaling differently. If you call
this before your main QApplication instance under a Gtk desktop (e.g.
Gnome), the ratio will always be set to 1.0 even if monitor scaling is set
to a value like 2.0:
app = QGuiApplication(sys.argv)
ratio = app.devicePixelRatio()
return ratio > 1.0
The serious problem with my earlier code from six days ago is that the Gdk
calls caused segfaults on some systems. Gnome developers were very kind to
point me in the right direction, which is to not call any Gdk code and use
x11 = xsettings.get_xsettings()
return x11.get(b'Gdk/WindowScalingFactor', 1) > 1
Exceptions need to be caught because xsettings does not run under KDE (I
did not test other Qt based desktops).
Fortunately PyQt community member Dmitry Shachnev already did all the hard
work and wrote a GPL2+ xsettings Python module
-- thanks Dmitry!
Finally, as an aside, scaling under wayland is much improved over scaling
in X11. Hopefully the KDE devs can get wayland working this year.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt