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. Native title bar size for proper window placement ?

Native title bar size for proper window placement ?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 6.3k Views 2 Watching
  • 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by
    #1

    Hi everyone!

    How do I properly calculate the initial window position so that my windows title bar isn't cut off when spawning it at the top?

    Or is there a way to do this using Qt functions already?

    thx,
    Megamouse

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

      Hi,

      What exactly are you experiencing ?

      You can position it a 0.0 or at the center of the screen.

      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
      • MegamouseM Offline
        MegamouseM Offline
        Megamouse
        wrote on last edited by
        #3

        The thing is, we desire to spawn the window exactly at the position centered on top of the parent. But we don't want to cross the screen boundaries. Therefore we want to have the frame aligned with the screen edges.

        The problem now is that using setFramePosition(0,0) sometimes sets it a few pixels too much to the right of the left screen border.

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

          Why not use your main window geometry to place your other widget ?

          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
          • MegamouseM Offline
            MegamouseM Offline
            Megamouse
            wrote on last edited by Megamouse
            #5

            This is the behaviour we want:

            0_1515276928759_91efaf69-e6f9-4643-a748-29a92b4a624b-image.png

            This is the behaviour we see:

            0_1515277073426_73e92b62-f137-4499-bc63-0376890380f5-image.png

            Isn't there a way to get the desired outcome with a normal Qt function that just handles these cases for us?
            Like a flag RespectScreenBorders

            Edit: Please note that the desired rectangles in the second picture is what we get. I forgot to change the labels to "Result"

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

              No there's not. You can put your windows outside of the screen on purpose or you could be placing them in a secondary screen.

              Can you show the code you use to move the widgets around ?

              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
              • MegamouseM Offline
                MegamouseM Offline
                Megamouse
                wrote on last edited by
                #7

                our current code calculates the new window geometry() using availableGeometry().
                then we setGeometry() to resize and reposition the window in its constructor. This doesn't take the window titlebar into account though.

                So we just add 32 to our min y in order to make space for the titlebar. this works just fine on windows 10. but we want to support any platform equally.

                Using setFramePosition() works well in that regard, unless we set it to (0,0). That's when we see the behavior in the picture above to the top left. And having it at the bottom obviously lets it go too far down into the taskbar.

                the best solution would be to only use setFramePosition when our calculated new position is (newpos < frameheight). But we can't get the frame margins without opening the window first and the mainwindow doesn't provide these margins.

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

                  You should use frameGeometry.

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

                  V 1 Reply Last reply
                  1
                  • MegamouseM Offline
                    MegamouseM Offline
                    Megamouse
                    wrote on last edited by
                    #9

                    I suppose the window has to be created before the frame is known.
                    But we need the frame geometry beforehand.

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

                      The geometry of the frame is not known before the widget is shown.

                      The showEvent method might be of help.

                      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
                      • MegamouseM Offline
                        MegamouseM Offline
                        Megamouse
                        wrote on last edited by
                        #11

                        Thanks, that seems to work. Although it's weird that frameMargins().left() returns a number way too high on my scaling (13). The top() is correct with 58 on my setup.
                        This makes the frame still show the horizontal displacement. I'll have to just force it to 0 and use a combination of setGeometry and setPosition to work around this.

                        1 Reply Last reply
                        0
                        • SGaistS SGaist

                          You should use frameGeometry.

                          V Offline
                          V Offline
                          Violet Giraffe
                          wrote on last edited by Violet Giraffe
                          #12

                          @SGaist said in Native title bar size for proper window placement ?:

                          You should use frameGeometry.

                          How do you mean? frameGeometry() is a getter, but there is no corresponding setter.

                          SGaistS 1 Reply Last reply
                          0
                          • V Violet Giraffe

                            @SGaist said in Native title bar size for proper window placement ?:

                            You should use frameGeometry.

                            How do you mean? frameGeometry() is a getter, but there is no corresponding setter.

                            SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @Violet-Giraffe That was to retrieve the information and use it in the following calculations.

                            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
                            1

                            • Login

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