Mac vs Windows scaling (same app much smaller on Windows)
-
I have to create a QML Python app that will look somewhat the same on Mac and Windows. But by default, my attempts yield results that are MUCH different in size (see picture).
I'm running both on the same physical screen, with Windows under Parallels, and my screen scaling is set up so that the user experience is similar between Mac and Windows for most other programs (including QT Creator itself). Yet the QML app is a massively different size.
Why is this? And is there a way to set the global scaling of the QML to make the Windows version bigger (the Mac OS version looks basically "correct")? Any other approach I could think of to deal with this programmatically seems like it would be very messy, and probably prevent me from using QT designer at all, which would be a giant disappointment.
-
It turns out the solution to this is simple, though I had to read a whole bunch of confusing descriptions of scalability. It really should be easier to find. And the Qt support pages on the topic could be less confusing.
https://stackoverflow.com/questions/41331201/pyqt-5-and-4k-screen
Put this in your setup code before creating the QGuiApplication, to support High DPI scaling on Windows:
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" sys.argv += ['--style', 'fusion'] app = QGuiApplication(sys.argv)
The font scaling ends up a little bit different, but that is acceptable for my use case.
For C++ users, look here:
https://doc.qt.io/qt-5/qtquickcontrols2-highdpi.html
Whew! I was getting nervous about my decision to create this cross platform UI.