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

QScreen geometry & availableGeometry returns weird values



  • I have 2 4k monitors set to scale at 150% on Windows 10 and I don't think the numbers are working out right for me. Here's my code:

            int screen_idx = 1;
            QList<QScreen*> screens(QGuiApplication::screens());
            Q_FOREACH( auto screen, screens)
            {
                const QRect screen_rect(screen->availableGeometry());
                const QRect pixel_rect(screen->geometry());
        
                qDebug() << "Screen #" << screen_idx << ": screen_rect: " << screen_rect << ", pixel_rect= " << pixel_rect;
                ++screen_idx;
            }
    

    and here is the output:

    Screen # 1 : screen_rect:  QRect(0,0 2560x1400) , pixel_rect=  QRect(0,0 2560x1440)
    Screen # 2 : screen_rect:  QRect(3840,0 2560x1400) , pixel_rect=  QRect(3840,0 2560x1440)
    

    Now one or both of those QRect for the sizes should be 3840x2160. The docs for geometry() in specific say:

    This property holds the screen's geometry in pixels
    

    Those are not pixels. Those are scaled pixels (2560x1.5=3840, 1440x1.5=2160). How do I get the actual number of pixels on each display?



  • Hi, I think it depends on what DPI awareness you code (or rather your .exe file) is set to. Here's a quick way to test, create a text file called qt.conf with this contents:

    [Platforms]
    WindowsArguments = dpiawareness=1
    

    and place that file in the same directory as your .exe file. Restart your app, does this change the output?



  • Yes, I did realize I forgot one other piece of info. I do set a couple things:

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
    

    But still - I just want the desktop size in pixels, so I can place my windows correctly.



  • I've opened a Qt bug to track this: https://bugreports.qt.io/browse/QTBUG-84206


Log in to reply