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. How to automatically position dock widgets?

How to automatically position dock widgets?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 2.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 1 Jul 2021, 15:51 last edited by
    #1

    Hello everyone, hope all is well! Currently, I am working on a function that displays a dock widget once a push button is clicked. I had no problems getting that working. However, I would like to be able to set the size and the position of the docks when they are created. Even more specifically, I also have a function that displays four docks when another button is clicked. My goal for this specific function is to display four dock windows as shown here:

    Screen Shot 2021-07-01 at 10.43.28 AM.png

    However, I have only been able to make such a layout by manually doing it once the app is running. I would like users to have this performed for them automatically as soon as they click the button. I am currently using the ui editor to implement my dock widgets, hiding them in the program, and then (in the program) showing them once a certain button is clicked.

    In short, my main question is: how do you set the size and position of a dock widget when it first appears on screen.

    M 1 Reply Last reply 1 Jul 2021, 16:18
    0
    • ? A Former User
      1 Jul 2021, 17:22

      @mrjj Thank you for your response! I believe they are floating dock widgets but default.

      Two Follow-Up Questions:

      1. Do the setGeometry/move methods make the docks unable to change size after they are called? I would still like the docks to be movable/resizable after they are initially sized/placed.
      2. Let's say I want to position two of these widgets in the top dock window and two in the bottom dock window? Does move() accomplish this? Or is there another method that I need to call?
      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 1 Jul 2021, 17:28 last edited by mrjj 7 Jan 2021, 17:29
      #4

      @WesLow
      Hi
      Ok. just asking as docked Docks can be moved. but when floating they are just windows.

      1. nope it simply moves the widget around on the screen. like if you dragged them there.
      2. move can do it. it's much like setGeo except it don't requires you to specify width, height also.

      https://doc.qt.io/qt-5/qwidget.html#pos-prop

      ? 1 Reply Last reply 1 Jul 2021, 19:52
      2
      • ? A Former User
        1 Jul 2021, 15:51

        Hello everyone, hope all is well! Currently, I am working on a function that displays a dock widget once a push button is clicked. I had no problems getting that working. However, I would like to be able to set the size and the position of the docks when they are created. Even more specifically, I also have a function that displays four docks when another button is clicked. My goal for this specific function is to display four dock windows as shown here:

        Screen Shot 2021-07-01 at 10.43.28 AM.png

        However, I have only been able to make such a layout by manually doing it once the app is running. I would like users to have this performed for them automatically as soon as they click the button. I am currently using the ui editor to implement my dock widgets, hiding them in the program, and then (in the program) showing them once a certain button is clicked.

        In short, my main question is: how do you set the size and position of a dock widget when it first appears on screen.

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 1 Jul 2021, 16:18 last edited by mrjj 7 Jan 2021, 16:20
        #2

        @WesLow
        Hi
        Are those floating DockWidgets?
        You can use move() and resize()
        or setGeometry

        There is also support in MainWindow for storing a state

        https://forum.qt.io/topic/69899/can-i-save-restore-the-current-state-pos-size-of-a-qdockwidget/3

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on 1 Jul 2021, 17:22 last edited by
          #3

          @mrjj Thank you for your response! I believe they are floating dock widgets but default.

          Two Follow-Up Questions:

          1. Do the setGeometry/move methods make the docks unable to change size after they are called? I would still like the docks to be movable/resizable after they are initially sized/placed.
          2. Let's say I want to position two of these widgets in the top dock window and two in the bottom dock window? Does move() accomplish this? Or is there another method that I need to call?
          M 1 Reply Last reply 1 Jul 2021, 17:28
          0
          • ? A Former User
            1 Jul 2021, 17:22

            @mrjj Thank you for your response! I believe they are floating dock widgets but default.

            Two Follow-Up Questions:

            1. Do the setGeometry/move methods make the docks unable to change size after they are called? I would still like the docks to be movable/resizable after they are initially sized/placed.
            2. Let's say I want to position two of these widgets in the top dock window and two in the bottom dock window? Does move() accomplish this? Or is there another method that I need to call?
            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 1 Jul 2021, 17:28 last edited by mrjj 7 Jan 2021, 17:29
            #4

            @WesLow
            Hi
            Ok. just asking as docked Docks can be moved. but when floating they are just windows.

            1. nope it simply moves the widget around on the screen. like if you dragged them there.
            2. move can do it. it's much like setGeo except it don't requires you to specify width, height also.

            https://doc.qt.io/qt-5/qwidget.html#pos-prop

            ? 1 Reply Last reply 1 Jul 2021, 19:52
            2
            • M mrjj
              1 Jul 2021, 17:28

              @WesLow
              Hi
              Ok. just asking as docked Docks can be moved. but when floating they are just windows.

              1. nope it simply moves the widget around on the screen. like if you dragged them there.
              2. move can do it. it's much like setGeo except it don't requires you to specify width, height also.

              https://doc.qt.io/qt-5/qwidget.html#pos-prop

              ? Offline
              ? Offline
              A Former User
              wrote on 1 Jul 2021, 19:52 last edited by
              #5

              @mrjj Thank you again! One last question as far as the reset/setGeometry functions go: is there a way to set the width of the dock widget to be equal to half the size of its parent window? For example, could you call something like dockWidget->setWidth(MainWindow/2)? Once again, thank you for all of your help!

              M 1 Reply Last reply 1 Jul 2021, 20:04
              0
              • ? A Former User
                1 Jul 2021, 19:52

                @mrjj Thank you again! One last question as far as the reset/setGeometry functions go: is there a way to set the width of the dock widget to be equal to half the size of its parent window? For example, could you call something like dockWidget->setWidth(MainWindow/2)? Once again, thank you for all of your help!

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 1 Jul 2021, 20:04 last edited by
                #6

                @WesLow

                hi
                yes something like

                int hw = MainWindow->width() /2;
                dockWidget->resize( hw, dockWidget->height() );
                
                ? 2 Replies Last reply 1 Jul 2021, 20:06
                0
                • M mrjj
                  1 Jul 2021, 20:04

                  @WesLow

                  hi
                  yes something like

                  int hw = MainWindow->width() /2;
                  dockWidget->resize( hw, dockWidget->height() );
                  
                  ? Offline
                  ? Offline
                  A Former User
                  wrote on 1 Jul 2021, 20:06 last edited by
                  #7

                  @mrjj Thank you very much!

                  1 Reply Last reply
                  1
                  • M mrjj
                    1 Jul 2021, 20:04

                    @WesLow

                    hi
                    yes something like

                    int hw = MainWindow->width() /2;
                    dockWidget->resize( hw, dockWidget->height() );
                    
                    ? Offline
                    ? Offline
                    A Former User
                    wrote on 1 Jul 2021, 20:46 last edited by
                    #8

                    @mrjj Having trouble with two things:

                    1. Calling MainWindow. Should I call this instead?
                    2. Seeing the resize method work at all. Is this because the dockWidgets are within dockWidget areas?

                    Thank you, in advance, for your time, help, and consideration!

                    M 1 Reply Last reply 1 Jul 2021, 20:57
                    0
                    • ? A Former User
                      1 Jul 2021, 20:46

                      @mrjj Having trouble with two things:

                      1. Calling MainWindow. Should I call this instead?
                      2. Seeing the resize method work at all. Is this because the dockWidgets are within dockWidget areas?

                      Thank you, in advance, for your time, help, and consideration!

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 1 Jul 2021, 20:57 last edited by
                      #9

                      @WesLow
                      Hi

                      1. well if you are inside a MainWindow function, then no need to use this or the variable name
                      int hw = width() /2;//  ( same as this->width() ) 
                      dockWidget->resize( hw, dockWidget->height() );
                      
                      1. well if the Docks are docked. (versus floating as windows)
                        then resize wont do anything as such.
                        In this case, the size of the internal widget often gives the size of the DockWidget.

                      Maybe im not sure what you ask here.

                      Can you maybe show what you did ?

                      ? 1 Reply Last reply 4 Jul 2021, 02:00
                      2
                      • M mrjj
                        1 Jul 2021, 20:57

                        @WesLow
                        Hi

                        1. well if you are inside a MainWindow function, then no need to use this or the variable name
                        int hw = width() /2;//  ( same as this->width() ) 
                        dockWidget->resize( hw, dockWidget->height() );
                        
                        1. well if the Docks are docked. (versus floating as windows)
                          then resize wont do anything as such.
                          In this case, the size of the internal widget often gives the size of the DockWidget.

                        Maybe im not sure what you ask here.

                        Can you maybe show what you did ?

                        ? Offline
                        ? Offline
                        A Former User
                        wrote on 4 Jul 2021, 02:00 last edited by
                        #10

                        @mrjj Thank you very much, this helped!

                        1 Reply Last reply
                        0

                        7/10

                        1 Jul 2021, 20:06

                        • Login

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