Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set QT_AUTO_SCREEN_SCALE_FACTOR behavior via API?

Tags:

c++

qt

qt5.6

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?

like image 632
Horst Walter Avatar asked Oct 25 '25 07:10

Horst Walter


1 Answers

The following should work

qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");

like image 185
Marc Van Daele Avatar answered Oct 27 '25 21:10

Marc Van Daele



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!