2 horizontal layouts, 1 with fixed height

  • I'm using Qt Designer to create a page with a navigation bar (using buttons at the top of the page inside a horizontal layout) and a message in the lower horizontal layout. The problem I'm having is the 2 layouts take half of the screen each. I want the top horizontal layout to have a fixed height and the lower one to take the remaining screen. I don't seem to find any property in the horizontal layout that can fix this problem in Design mode.

    How can I have 2 layouts, one with fixed size?

    Here is an image to help visualize it


  • Qt Champions 2016

    you can use LayoutStretch 2,1 to share other than half/half.
    That said, you set minimum size on the widget you insert into the layout
    so for your design, the top bar,you would set MInimumHeight to say 64
    and it would not get bigger.

    So with layouts, u set constraints on the widgets, not on the layouts.

  • @mrjj

    For some reason it's not working so I will list what I do step by step :

    1. I have QStackedWidget with contains 2 pages (page 2 is the one that will have the 2 layouts )

    2. drag and drop 2 horizontal layouts into page2

    3. selected page 2, right-click, choose layout, lay out vertically (at this point each of the layout fill out half of the screen)

    4. when I select the top layout and change LayoutStretch to 1, the bottom layout changes LayoutStretch automatically to 0. If I change the bottom layout to 2 and select the top layout to check its value I find that it was automatically changed to 2. If I go back to the bottom layout I find that LayoutStretch is 0.

    5. drag and drop a button in the top layout and change it's maximum size to width = 125 and height = 60, has no effect on the top layout, still takes half of the screen.

    What am I still doing wrong?

  • Qt Champions 2016

    1. You should no drag layout to page. Its rarely use standalone.
      Right click is the way to add layout.

    Try this

    Create page 3. ( so we have clean to play with)
    Drag 2 widgets to it.
    Right click the page and select the Vert layout.
    (widgets should spit it half/half)
    Now click on top widget
    and set its Maximum Height to 64.
    It should be top bar aliek now. place buttons etc in it.

    ps. and dont worry. layout are kinda strange to learn at first. later they be your best friends.

  • @mrjj

    Using 2 widgets instead of horizontal layouts worked but it has its problems.

    First, I like the layout to be wrap around multiple buttons to keep them lined up perfectly.

    Second, if I resize the window a few of the buttons disappear.

    Is there a way to get around those 2 problems?

  • Qt Champions 2016

    just give the top widget a layout too
    so u can control the buttons. like a Horz or Grid one.

    Im not sure what means
    " layout to be wrap around multiple buttons"
    as buttons are inserted into a layout.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.