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. Position QWidget fully in screen, including window decoration

Position QWidget fully in screen, including window decoration

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 579 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I understand the difference between geometry() and frameGeometry(). What I need is a "setFrameGeometry", in order to position a window (borders, title bar, and all) nicely inside a screen.

    Lacking a setFrameGeometry, I looked for properties that would help me calculate the proper geometry (e.g. how high is the title bar, how wide are the borders), but didn't see anything.

    My next try was to calculate the correct geometry to set by calculating offsets between frameGeometry and geometry. But at least inside the constructor, the values for frameGeometry don't make sense, so no help there.

    Any ideas?

    jsulmJ 1 Reply Last reply
    0
    • A Asperamanca

      I understand the difference between geometry() and frameGeometry(). What I need is a "setFrameGeometry", in order to position a window (borders, title bar, and all) nicely inside a screen.

      Lacking a setFrameGeometry, I looked for properties that would help me calculate the proper geometry (e.g. how high is the title bar, how wide are the borders), but didn't see anything.

      My next try was to calculate the correct geometry to set by calculating offsets between frameGeometry and geometry. But at least inside the constructor, the values for frameGeometry don't make sense, so no help there.

      Any ideas?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Asperamanca So, you actually want to maximise the window, right?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Asperamanca So, you actually want to maximise the window, right?

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @jsulm No. I want to manually set the size and position, because e.g. I want the window to stretch two screens. That cannot be done via maximize.

        jsulmJ 1 Reply Last reply
        0
        • A Asperamanca

          @jsulm No. I want to manually set the size and position, because e.g. I want the window to stretch two screens. That cannot be done via maximize.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Asperamanca I don't think you can get the size of the window decorations using Qt as those are drawn by the window manager of your OS, not Qt.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Asperamanca I don't think you can get the size of the window decorations using Qt as those are drawn by the window manager of your OS, not Qt.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            This code works for me. Still have to look whether it's portable, but so far, I see nothing indicating the contrary:

            void CWidget::setFrameGeometry(const QRect rect)
            {
                (void) winId();
                const auto* const pWindow = windowHandle();
                QMargins margins;
                if (pWindow)
                {
                    margins = pWindow->frameMargins();
                }
            
                const auto adjustedRect = rect.adjusted(margins.left(),
                                                        margins.top(),
                                                        margins.right(),
                                                        margins.bottom());
            
                setGeometry(adjustedRect);
            }
            

            I just wonder why they didn't provide this as a standard QWidget method

            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 Extensions
            • Unsolved