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

How to get the REAL desktop size WITHOUT the areas occupied by Windows?



  • I'm creating a qml application which is DPI aware and supports multiple monitors. For a particular task, I need to determine the exact geometry of the screen on which my mouse is, WITHOUT the areas used by Windows, like e.g. the taskbar.

    To achieve that, I wrote the following code, which I execute from an onMouseYChanged() signal located in a MouseArea:

    ...
    // get the mouse position onto the desktop
    var mousePos    = mapToGlobal(mouseX, mouseY);
    var screenIndex = 0;
    
    // iterate through screens
    for (var i = 0; i < Qt.application.screens.length; ++i)
    {
        // get screen bounds
        var curScreen  = Qt.application.screens[i];
        var rectLeft   = curScreen.virtualX;
        var rectTop    = curScreen.virtualY;
        var rectRight  = curScreen.virtualX + curScreen.width;
        var rectBottom = curScreen.virtualY + curScreen.height;
    
        // is mouse on this screen?
        if (mousePos.x >= rectLeft && mousePos.y >= rectTop && mousePos.x <= rectRight && mousePos.y <= rectBottom)
        {
            screenIndex = i;
            break;
        }
    }
    
    // get the current screen
    var screen = Qt.application.screens[screenIndex];
    
    console.log(screen.desktopAvailableHeight + " - " + screen.height + " - " + screenIndex);
    ...
    

    All works fine with this code, except one thing, which is the most important for me. Indeed the value of screen.desktopAvailableHeight is ALWAYS the same of the screen.height one, whatever the screen I test.

    However, if I refer to the Screen.desktopAvailableHeight documentation:
    "This contains the available height of the collection of screens which make up the virtual desktop, in pixels, excluding window manager reserved areas such as task bars and system menus."

    As this is absolutely not the result I get, what am I doing wrong? Is my above code correct? And if not, how can I get the REAL desktop size WITHOUT the areas occupied by Windows?


Log in to reply