tags:

views:

14

answers:

1

Hello all, I've got a vBoxLayout which contains 3 simple buttons, when I increase the size of the widget containing the layout, the spacing between the buttons increases. I would like to stop this behaviour and keep the buttons in a consistent and compact layout, regardless of the size of the parent widget. This is what I've got so far, but it doesn't change the spacing, any suggestions?, thanks.

    button_layout = new QVBoxLayout ;
    button_layout -> setSpacing(0);
    button_layout -> setContentsMargins(0,0,0,0);
+1  A: 

You'll want to add a stretchable spacer to the layout:

button_layout = new QVBoxLayout ;
button_layout -> setSpacing(0);
button_layout -> setContentsMargins(0,0,0,0);
button_layout -> addStretch();
button_layout -> addWidget(button_1);
button_layout -> addWidget(button_2);
button_layout -> addWidget(button_3);

This would cause the buttons to always be on the bottom of the containing widget. Note that the horizontal portion would still stretch if your widget expanded that way; to fix that, you need to either wrap in another (HBox) layout or switch to a grid layout.

Caleb Huitt - cjhuitt
wow, thanks, I had intuitively thought that stretches were actually doing the opposite of what you describe.
Gearoid Murphy