Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.html

    The 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



  • @jeremy_k Thanks, I did give those docs a read, but they weren't particularly helpful. The solution was to use the devicePixelRatio() method of QScreen for appropriate scaling.


Log in to reply