Can I set QT_AUTO_SCREEN_SCALE_FACTOR behavior via API?

Horst Walter picture Horst Walter · Mar 8, 2016 · Viewed 8.4k times · Source

Can I set the QT_AUTO_SCREEN_SCALE_FACTOR 1 behavior via an API call rather than by the environment variable? I want to detect if my Qt application is running on a high dpi screen, then set the scaling accordingly.

I have tried to set it at the very beginning of main, which does not work

QProcessEnvironment::systemEnvironment().insert("QT_AUTO_SCREEN_SCALE_FACTOR", "1");

It's meant to be used along with QProcess, to set the environment for child processes. It cannot be used to change the current process's environment.

Follow up of Style sheets / Qt Designer support for high dpi screens?

Answer

Marc Van Daele picture Marc Van Daele · Mar 23, 2016

The following should work

qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");