4

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?

Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228

1 Answers1

9

The following should work

qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");

Marc Van Daele
  • 2,856
  • 1
  • 26
  • 52
  • 2
    Excellent, at least I now can check for high DPI and set the flag accordingly. Remark: I have to set this at a very early stage (first line of `main`, otherwise it does not show any effect). – Horst Walter Mar 23 '16 at 20:39
  • 1
    i dont think you need to check for DPI, if you have lowdpi or highdpi thanks to the AUTO part of the variable it should work as expected automatically – michnovka Oct 25 '16 at 23:51