Qt 4.8 vs. 5.0.1 inconsistent behavior of QDesktopWidget on Windows 8 (virtual vs. non virtual display & screen resolution)



  • I have an issue with Qt 5.0.1 detecting my screen resolution incorrectly. I've opened a bug report "QTBUG-30063":https://bugreports.qt-project.org/browse/QTBUG-30063 but maybe someone here had similar problem, or can explain what is going on?

    It all boils down to the QDesktopWidget detecting wrong screen settings, when Qt 4.8.4 works as expected (the resolution set in windows is 1920x1080 px, that is what specification of my Tablet ACER w700 also says).

    @
    #include <QApplication>
    #include <QDesktopWidget>
    #include <QDebug>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);

    QDesktopWidget* d = QApplication::desktop();
    qDebug() << "screen count:      " << d->screenCount();
    qDebug() << "screen number:     " << d->screenNumber();
    qDebug() << "primary screen:    " << d->primaryScreen();
    qDebug() << "is virtual dt:     " << d->isVirtualDesktop();
    qDebug() << "screen geometry:   " << d->screenGeometry();
    qDebug() << "available geometry:" << d->availableGeometry();
    qDebug() << "desktop size:      " << d->size();
    
    return 0;
    

    }
    @

    Qt 5.0.1 reports:
    @
    screen count: 1
    screen number: 0
    primary screen: 0
    is virtual dt: false
    screen geometry: QRect(0,0 1536x864)
    available geometry: QRect(0,0 1536x826)
    desktop size: QSize(1536, 864)
    @

    Qt 4.8.4 reports:
    @
    screen count: 1
    screen number: 0
    primary screen: 0
    is virtual dt: true
    screen geometry: QRect(0,0 1920x1080)
    available geometry: QRect(0,0 1920x1032)
    desktop size: QSize(1920, 1080)
    @

    So the difference is in detecting a screen as a virtual desktop by Qt 4.8.4 and as a non virtual display by 5.0.1, then the resolutions are also different. The Qt 4.8.4 seems to be correct, and it works well in fact; with 5.0.1 I have various problems like not hiding Windows taskbar in full screen mode and translating touch signals incorrectly, which I think is a result of incorrect resolution.

    Did anyone see anything like this? Can I force virtual desktop settings in Qt 5.0.1?

    Thanks,
    Max



  • Finally got it: The problem with "incorrect" values is that SetProcessDPIAware() function has to be called before GetMonitorInfo, GetSystemMetrics, EnumDisplayMonitors or alike are called. The values returned by these functions are scaled according to a scaling factor that Windows uses to scale interface, so they will differ from the actual screen resolution if scaling is not 100%.

    Qt 4.8.4 is calling SetProcessDPIAware in qapplication_win.cpp during initialization, and therefore gets proper values, while Qt 5.0.1 doesn't do it.

    I hope it will be fixed in the future releases, for now, the workaround is to include <Windows.h> in main.cpp and call SetProcessDPIAware(), before any Qt calls:

    @
    #include <QApplication>
    #include <QDesktopWidget>
    #include <QDebug>
    #include <Windows.h>

    int main(int argc, char **argv)
    {
    SetProcessDPIAware();

    QApplication app(argc, argv);
    
    QDesktopWidget* d = QApplication::desktop();
    qDebug() << "screen geometry:   " << d->screenGeometry();
    qDebug() << "available geometry:" << d->availableGeometry();
    qDebug() << "desktop size:      " << d->size();
    
    return 0;
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.