QScreen returning the wrong size for my monitor
-
Hi all,
Currently I have two 4k monitors and a 1920x1080 tablet connected to my PC, running Windows 10 and Qt 5.15. I have the following loop:
std::vector<QSize> resolutions; std::vector<float> dpis; for (const auto* screen : QGuiApplication::screens()) { resolutions.push_back(screen->size()); dpis.push_back(screen->logicalDotsPerInch()); }
I would expect the values for my resolutions to be
{ QSize(3840 , 2160), QSize(3840 , 2160), QSize(1920, 1080)}
. However, for some strange reason, all of my values are halved, and I get{ QSize(1920, 1080), QSize(1920, 1080), QSize(960, 540)}
. Is there something weird about the size() routine that I'm missing? The units should be pixels, so I'm really thinking this is a bug with Qt.I'll add that window sizes are also similarly incorrect when I try to query them.
QGuiApplication::primaryScreen
also errantly returns 1920x1080 as my screen dimensions, which should be 4k. -
It sounds like high DPI scaling by a factor of 2.0.
https://doc.qt.io/qt-5/highdpi.html
https://doc.qt.io/qt-6/highdpi.htmlThe Qt 5 version goes into more detail.
-
@jeremy_k Thanks, that looks like a very possible explanation.
Is there a way to check for the value of this factor at runtime? If not, I'm out of luck. Not sure if it matters, but I'm getting DPI values of 96 across the board for each screen.
-
Check the linked docs. There's been an evolution of how scaling is reported and controlled.
For text, specifying in sizes in points instead of pixels should abstract the problem. If everything works as intended.96 dpi is or was a standard of sorts. Pulling from the Qt 5 high dpi documentation:
The former is around twice the standard 96 DPI desktop resolution
-
@feistykittykat Thank you very much! That worked for me as well. Was driving me nuts that it used to work when I was doing 5.x development and since going to 6.2.1 I have found a lot of gotchas in my code!