PDA

View Full Version : How do I squash a widget in a grid layout down to the bottom to its minimum size?



enjoysmath
10th August 2015, 07:43
I have a widget I made in Qt Designer and a QGraphicsView. I'd like:

[QGraphicsView]
[ " ]
[ " ]
[ " ]
[ " ]
[ " ]
[MyCustomWidget]

Instead, the layout is coming out like this:

[QGraphicsView]
[MyCustomWidget]

ie. 50 /50 split of vertical space. I've played around with the row/column span versions of gridLayout.addWidget(), and they didn't make any difference.

Thanks.

ChrisW67
10th August 2015, 09:12
The layout allocates the available space between the widgets that want it. If you place nothing in rows 1-5 of the grid then there is nothing to occupy space there, so the two actual widgets get the space. You have a range of options: set a maximum height on the custom widget, setRowStretch() to 1 for all rows except the last which gets 0, put (expanding) vertical spacers in the empty grid rows. What effect are you trying to achieve with the empty grid squares?

enjoysmath
10th August 2015, 19:51
The "empty grid rows" will not be empty they will be occupied by the QGraphicsView. I want a maximized QGraphicsView and a minimized lower custom widget.

Added after 13 minutes:

Setting the size policy of either subwidget does nothing. Setting the row stretch or setting the rowSpan do nothing either.

anda_skoa
10th August 2015, 21:14
So you have two widgets?
Why use a grid layout at all?
Sounds like a QVBoxLayout use case to me.

Cheers,
_