Nitzan Tomer
Nitzan Tomer

Reputation: 164357

Widget or layout to fill parent

What I'm trying to accomplish is a very simple and straight forward need, or I thought, but for the life of me, I can't seem to find a way to do it.

In my qt application I want to be able to make a widget or a layout fill the entire space of the parent widget.

For example, let's say I want to have a label with a fixed height and beneath it a stacked widget which occupies the rest of the height of the window. Here's what I do in the qt-creator designer:

  1. drag a label to the form
  2. drag a stacked widget to the form
  3. select both of them and then right click > lay out > lay out vertically
  4. select the verticalLayout object and in the layoutStretch property have 0,1

Now, how do I make the verticalLayout occupy all of the width/height of the centralWidget? Nothing seems to work for me.

Thanks.

Upvotes: 7

Views: 7565

Answers (1)

You've merely put two widgets in a layout, but you also need a layout on their parent widget - on the form. Here's what you should do instead:

  1. Drag any number of widgets to the parent widget (the form). Arrange them roughly the way you want them to be once laid out.

  2. Right click on the form. Select "Lay out >" submenu.

  3. Choose the desired layout from the menu: horizontal, vertical, grid, etc.

Upvotes: 5

Related Questions