开发者

How to create a compact Qt4 vBoxLayout

I've got a vBoxLayout which contains 3 simple buttons, when I increase the size of the widget开发者_JS百科 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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜