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 set different size of layouts in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to set different size of layouts in Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 11.4k 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
    And92
    wrote on last edited by And92
    #1

    I put on the central widget QHBoxLayout in Qt Designer. Then I put 2 QVBoxLayout's in this QHBoxLayout. They occupy the space of equal width, as can be seen in the Picture.
    layout.png
    The question is: how to make them of different width? For example, 1:3 (left QVBoxLayout width : right QVBoxLayout width).
    And how to make it in Qt Designer and from the source code?
    What is layoutStretch field on the right bottom of the picture and how to use it?
    Could You, please, give some code example.

    jsulmJ 1 Reply Last reply
    0
    • A And92

      How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?

      B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #4

      @And92
      If you click on the horizonLayout, The layoutStretch should be "0, 0".
      You can set it to "1, 3".

      1 Reply Last reply
      3
      • A And92

        I put on the central widget QHBoxLayout in Qt Designer. Then I put 2 QVBoxLayout's in this QHBoxLayout. They occupy the space of equal width, as can be seen in the Picture.
        layout.png
        The question is: how to make them of different width? For example, 1:3 (left QVBoxLayout width : right QVBoxLayout width).
        And how to make it in Qt Designer and from the source code?
        What is layoutStretch field on the right bottom of the picture and how to use it?
        Could You, please, give some code example.

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

        @And92 There is layoutStretch property for that

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

        1 Reply Last reply
        3
        • A Offline
          A Offline
          And92
          wrote on last edited by And92
          #3

          How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?

          B jsulmJ JonBJ 3 Replies Last reply
          0
          • A And92

            How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?

            B Offline
            B Offline
            Bonnie
            wrote on last edited by
            #4

            @And92
            If you click on the horizonLayout, The layoutStretch should be "0, 0".
            You can set it to "1, 3".

            1 Reply Last reply
            3
            • A And92

              How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?

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

              @And92 Well, select the layout containing your vertical layouts and in that layout change layoutStretch (for example to 1,2).

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

              1 Reply Last reply
              0
              • A And92

                How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @And92 said in How to set different size of layouts in Qt?:

                Could You, please, give any link? And how to do it from the code?

                Start from https://doc.qt.io/qt-5/qboxlayout.html#setStretch, and other references to stretch on that page and elsewhere, like https://doc.qt.io/qt-5/layout.html#stretch-factors. Also, once you have set layoutStretch in the Designer, you can look in the uic-generated code (ui_*.h files) to see what statements that is producing at run-time.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  And92
                  wrote on last edited by
                  #7

                  Thank You very much, @Bonnie and @jsulm, I got the idea. It is simple. My error was that i tried to set layoutStretch property in both of QVBoxLayout, but should modify the layoutStretch property of the QHBoxLayout layout, containing them.
                  @JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.
                  Unfortunately, I do not know how to mark the answer as a solution here.

                  jsulmJ JonBJ 2 Replies Last reply
                  0
                  • A And92

                    Thank You very much, @Bonnie and @jsulm, I got the idea. It is simple. My error was that i tried to set layoutStretch property in both of QVBoxLayout, but should modify the layoutStretch property of the QHBoxLayout layout, containing them.
                    @JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.
                    Unfortunately, I do not know how to mark the answer as a solution here.

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

                    @And92 Click on the 3 dots icon in bottom right of the post and then "Mark this post as correct answer".

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

                    1 Reply Last reply
                    0
                    • A And92

                      Thank You very much, @Bonnie and @jsulm, I got the idea. It is simple. My error was that i tried to set layoutStretch property in both of QVBoxLayout, but should modify the layoutStretch property of the QHBoxLayout layout, containing them.
                      @JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.
                      Unfortunately, I do not know how to mark the answer as a solution here.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #9

                      @And92 said in How to set different size of layouts in Qt?:

                      @JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.

                      https://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html
                      http://zetcode.com/gui/qt5/layoutmanagement/

                      Sorry, but I didn't write the Qt docs :), that's what I could spot.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        And92
                        wrote on last edited by
                        #10

                        @JonB, sorry. Thank You for Your support. It was helpful.

                        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