setting QT_DEVICE_PIXEL_RATIO for a specific application
-
Hello,
under Windows 8.1, I can force the pixel ratio by setting the system's environmnent variable QT_DEVICE_PIXEL_RATIO.
This is however applied to all my Qt applications.
Is it possible to set that variable specifically to one application?
I read about qt.conf file, but I am not sure what I have to put in there. e.g.[Environment] setx QT_DEVICE_PIXEL_RATIO 2
But that has no effect. The qt.conf file is located in the same folder as my application's executable.
-
Hi,
I haven't tested it but from a quick look at the doc:
[Platforms] WindowsArguments = dpiawareness=2
might to the trick
-
Thanks Samuel,
this (and other similar variants) don't work. I think your example just tells Qt to do automatic high-res display detection, but not force it (e.g. to test it on a low-res display system.
-
Sorry, my bad, I misread the signification of the variable.
Just one thing, do you want to do it from Qt Creator while developing your application ?
-
Thanks,
I need to be able to do it for the executable that is distributed.
-
Which version of Qt are you using ?
-
I am using Qt 5.5
-
As a workaround you could try calling qsetenv before instantiating your QApplication
-
Thanks again!
This works on Windows:
qputenv("QT_DEVICE_PIXEL_RATIO",QByteArray("2"));
Any similar functionality for Linux (and optionally Mac, but as far as I have tested it, Mac always recognizes high dpi displays)?
-
qputenv works also on OS X and Linux. IIRC yes OS X already handles that
-
Excellent, you are right, that also works on Linux.
Thanks a lot! -
Hi, I need to change the QT_DEVICE_PIXEL_RATIO to "auto" in windows 10.
I'm not a software developer and I have no idea how to do this I really appreciate if you can help me with this.
-
Hi and welcome to devnet,
If it's to test your application while using Qt Creator: go to the run part of the Project panel. There you can edit the environment variables. Add a new variable with the name QT_DEVICE_PIXEL_RATIO and in value write auto.
-
@SGaist said:
QT_DEVICE_PIXEL_RATIO
Hi,
I did set the variable to AUTO as you mentioned.
My app run fines on 1366768 screen resolution size. But if I keep my screen resolution to 1024768, UI gets cut. (cannot see buttons of my UI app).
What would be the probable way to fix my app to all resolution of screen? -
Are you using layouts to handle your widgets ?
-
If your application needs a minimal size then you can put your main widget in a QScrollArea. That way if your application doesn't fit, you'll have scroll bars to move up/down to access the rest of your UI.
-
Not really a last option. If the design of your UI is big enough to not fit some screen resolution you can either change the design to fit a larger set of screen resolution. or make it more modular under a certain size. A scrolling area is not a bad solution otherwise how would you browse internet ?