Setting Qt To Ignore Windows DPI Text Size Personalization
So, you have a C++ program with a Qt interface for Windows that you're releasing as a quick 'Version One'.
All is well and you're ready to ship... until you discover that DPI scaling in Windows resizes all label text by 125%, 150% or 200% while leaving buttons and labels at their set dimensions. The result with that scaling is an interface which is messy at best and unreadable at worst.
"Hey, no problem," you're thinking. "I'll just set Qt to ignore the Windows DPI setting and have the app drawn as we created it.
"Sure, the text will be smaller if the user is running Windows with a font scaled at 125% or 150% above normal, but everything will remain legible and laid out correctly in our app. We can revisit the GUI to do everything correctly later."
If this is a familiar tale for you, you already know there is no flag for setting Qt to ignore the Windows DPI setting.
What? Seriously?
You've seen the forum posts chiding that a proper Qt GUI should use a scalable layout. You've read the smarmy comments claiming that slapping together a new GUI with layouts should be easy for an experienced Qt developer to do. So easy, in fact, that the lack of documentation on the subject and complete absence of examples should be no deterrent to a Qt developer looking to create a layout capable of automatic scaling with Windows fonts.
Gee, thanks.
Give Me a Qt Quick Fix for High-DPI Displays Already!
Sure, rewriting that 'Version One' Qt GUI with scalable layouts would be awesome and all, but I'm new to Qt, have a hard release deadline, no time, and the number of users currently affected by the issue can be counted on one badly mutilated hand.
A full GUI re-write for an app which might end up discarded is the least responsible thing to do right now. Isn't there a way to tell Qt "Don't scale text to accommodate high-DPI displays"?
Why, yes there is! You can explicitly set the size of fonts in your Qt app with font.setPixelSize.
For example, this:
QApplication a(argc, argv);
QFont font = qApp->font();
font.setPixelSize(11);
qApp->setFont(font);
Will size all GUI fonts at 11 pixels in size regardless of the DPI settings on Windows.
It's simple, it's an imperfect solution, and it works.
Done. Ship it.
We can look at a proper font scaling solution and rebuild the GUI with Qt's DPI scalable layout magic after we've confirmed the app's Version One satisfies a genuine need.