<div dir="ltr"><div>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:</div><div><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-size:10.5pt">app = QGuiApplication(sys.argv)<br>ratio = app.devicePixelRatio()<br><span style="color:rgb(0,51,179)">del </span>app<br><span style="color:rgb(0,51,179)">return </span>ratio > <span style="color:rgb(23,80,235)">1.0</span></pre></div><div></div><div>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 xsettings instead:<br></div><div><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-size:10.5pt">x11 = xsettings.get_xsettings()<br><span style="color:rgb(0,51,179)">return </span>x11.get(<span style="color:rgb(6,125,23)">b'Gdk/WindowScalingFactor'</span>, <span style="color:rgb(23,80,235)">1</span>) > <span style="color:rgb(23,80,235)">1</span></pre></div><div>Exceptions need to be caught because xsettings does not run under KDE (I did not test other Qt based desktops).</div><div><br></div><div>Fortunately PyQt community member Dmitry Shachnev already did all the hard work and wrote a GPL2+ <a href="https://github.com/retext-project/retext/blob/master/ReText/xsettings.py">xsettings Python module</a> -- thanks Dmitry!</div><div><br></div><div>Finally, as an aside, scaling under wayland is much improved over scaling in X11. Hopefully the KDE devs can get wayland working this year.<br></div><div><br></div><div>Best,</div><div>Damon<br></div>-- <br><div dir="ltr"><a href="http://www.damonlynch.net" target="_blank">http://www.damonlynch.net</a><div></div><div></div><div></div></div></div>