Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QDesktopWindow::availableGeometry not excluding taskbar (Qt 5.2, Windows 7)
QtWS25 Last Chance

[SOLVED] QDesktopWindow::availableGeometry not excluding taskbar (Qt 5.2, Windows 7)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 9.3k 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.
  • E Offline
    E Offline
    edtasker
    wrote on last edited by
    #1

    I want my main window to have a maximized height but not necessarily a maximized width.

    my code is:

    @
    QDesktopWidget *desktop = QApplication::desktop();
    QRect desktopGeometry = desktop->availableGeometry();
    int desktopHeight = desktopGeometry.height();
    mainWindow.setFixedHeight(desktopHeight);
    @

    However, when running, the height is the full desktop, presumably availableGeometry isn't excluding the height of the taskbar (like it says that it will in the documentation). I'm using Qt 5.2 (edit). I'm running it on windows 7 (taskbar is not set to auto-hide).

    Any idea why availableGeomerty isn't excluding the taskbar, or any other ideas to set the height (but not width) to fill the screen

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you also add which version of Qt you are using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        edtasker
        wrote on last edited by
        #3

        [quote author="SGaist" date="1399534117"]Hi,

        Can you also add which version of Qt you are using ?[/quote]

        Added. Using Qt 5.2.

        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Hi, actually availableGeometry() is excluding the taskbar, perhaps you're thinking of screenGeometry()?

          Anyway, it's tricky when you call mainWindow.setFixedHeight(desktopHeight); because then you're only setting the client rect, then when Windows decorates your window with a title bar, minimize maximize etc. it gains additional height (on my Windows 7 32 pixels). And the taskbar is about the same pixel height :-)

          1 Reply Last reply
          0
          • E Offline
            E Offline
            edtasker
            wrote on last edited by
            #5

            Ah okay. Thanks. So do you know is there any way to set the height of the window, including title bar etc., to the available desktop height?

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zeljko
              wrote on last edited by
              #6

              I'm using qt-4.8.5 on win7 and availableGeometry() returns without taskbar size, but screenGeometry() returns complete size.So definitelly I have correct height.
              What showMaximized() says ? Is it normal , or it's over taskbar ?

              1 Reply Last reply
              0
              • E Offline
                E Offline
                edtasker
                wrote on last edited by
                #7

                Because adding the frame added extra height to my window, the solution was to:

                First call mainWindow.show(), when this is called windows adds the title bar and frame etc.

                The height of all the added stuff can then be calculated by subtracting mainWindow.geometry.height() from mainWindow.frameGeometry.height().

                Then the window can be resized to the height of the available screen geometry minus the calculated height of the frame etc.

                example:

                @
                mainWindow.show();
                int difference = mainWindow.frameGeometry.height() - mainWindow.geometry.height();
                int height = QApplication::desktop().availableGeometry.height() - difference;
                mainWindow.setFixedHeight(height);
                @

                1 Reply Last reply
                0

                • Login

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