Font point size weird behaviour on Windows
davidesalvetti last edited by
I know this problem has been approached a lot of times, but I didn't found a solution plus I have found a strange behaviour.
I' m developing an application on windows 10 with Qt 5.15.2 MinGw 32 bit. At the moment the application was used only on screen with 1920 x 1080 resolutions with the windows setting of the text size at 100% and everything works fine. I post a screen of 2 of our QLabel:
These labels have the exact same characteristics: the font family is MS Shell Dlg 2 and the point size is 8.
Now what I want to do is to run my application on the same screen with a 150% text scale factor. When I do this, I would like my application to do not scale the point size accordingly to this settings. In this situation I did not set any line from the High DPI Section of Qt and this is what I got:
As you can see, the "Min:" label is exactly of the same size of the screenshot before, while the "Max:" is increased in size under the effect of the 150% setting. But there are no difference between them in terms of point size! Just to be as clear as possible, I set the point size in the .ui file.
I investigated on this (at least for me) strange behaviour and I found out that the only difference between the 2 QLabel is that the "Max:" QLabel has been modified in point size in previous releases, and then in the current version was set at a point size of 8. In fact, if I replace the "Max:" QLabel with a new one without modifying the point size, this is what I get, always at 150%:
Then, if I try to update the point size of the "Min:" QLabel , for example at 10, I get the following on 150%:
And if I set it back to 8, always at 150%:
At the moment I have some text of the application that mantains the point size, and others that have been modified in point size, that change thei point size when setting 150%.
I hope I'm making myself clear, in case I'm not please ask me.
Now that I explained the problem I will explain what I' m trying to do. I would like that when using 150% or any other DPI setting, the texts do not increase their size, like the "Max:" QLabel in the last screenshoot I posted: in that screenshot the point size of "Max:" is 8, the same as the "Min:", but "Min:" but "Min:" has changed its size.
I' ve read the HIGH DPI Section, but I did not find something useful for my case.
I tried putting
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);in the main, before QApplication initialization, but the result was that all the dialogs were increased in size to make the text at 150% fit inside, losing the resolution.
Then I tried creating a qt.conf file near the executable with the following line inside:
[Platforms] WindowsArguments = dpiawareness=0
But I ended up with the same situation as before, where the dialogs sizes were increased to make the text at 150% fit inside.
I then tried to set the following lines before QApllication initialization:
qputenv("QT_SCREEN_SCALE_FACTORS", "1"); qputenv("QT_SCALE_FACTOR", "1");
But it behaves like if no settings were made and I obtained the same behaviour of the screenshoot above.
Since I have a 1920 x 1080, I would like the application to behave in the same way, even if the windows DPI is set to 100% or 150%. What can I do? Any hint or explanation for the strange behaviour above?
If you have any question or need other information or screenshot please ask me.
Thanks in advance.