Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to get the REAL desktop size WITHOUT the areas occupied by Windows?
Qt 6.12 LTS is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 281 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jeanmilostJ Offline
    jeanmilostJ Offline
    jeanmilost
    wrote on last edited by jeanmilost
    #1

    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?

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved