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?

Isn’t there a way to tell Qt “Don’t scale text to accommodate high-DPI displays”?

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();

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.

4 thoughts on “Setting Qt To Ignore Windows DPI Text Size Personalization”

  1. Actually, this is not enough, since Qt uses the DPI settings in several other places to determine the size metrics (it uses them e.g. in layouts, to determine spacing around items and the like). Fortunately, it’s possible to force Qt to ignore completely the OS DPI settings and default to 96 fake-DPIs everywhere doing:


    before instantiating the QApplication.

    1. Hey there, thanks for this info. With regard to the AA_Use96Dpi, how does this work in a PyQt/PySide context? I’m trying to work out what the appropriate syntax would be.

      1. Actually it looks like this might be the way:
        However, PySide doesn’t have this attribute as part of QtCore.Qt. It has other AA_ stuff, but not Use96Dpi.

        1. Hi Jeff,

          I’m afraid I’m not familiar with that particular library, but it looks like you’ve found the solution.

          Thanks so much for sharing that! It’s a simple fix which I’m sure others will find quite helpful.


Comments are closed.