Search code examples
c++qtqt5.6

Can I set QT_AUTO_SCREEN_SCALE_FACTOR behavior via API?


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?


Solution

  • The following should work

    qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");