Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: How to set the maximum width of a QVBoxlayout

Tags:

c++

qt

I currently have a horziontal layout that has two vertical layouts in it. Vlayout1 and VLayout2. Now I want to set a maximum width limit of VLayout1 so that if the form is expanded after that, only Vlayout1 expands.
Any suggestions on how I could accomplish this?

like image 409
Rajeshwar Avatar asked Nov 27 '13 10:11

Rajeshwar


People also ask

What is QVBoxLayout in Qt?

QVBoxLayout::QVBoxLayout(QWidget *parent)Constructs a new top-level vertical box with parent parent. The layout is set directly as the top-level layout for parent. There can be only one top-level layout for a widget. It is returned by QWidget::layout().

How do I add a horizontal spacer in Qt?

To place unused space left or right of the text edit put the QTextEdit into a QHBoxLayout and use one of the functions addSpacerItem() , addSpacing() or addStretch() to add spacing.

What is layout in Qt?

The Qt layout system provides a simple and powerful way of automatically arranging child widgets within a widget to ensure that they make good use of the available space.


1 Answers

You can do a "hack" and place your layout inside a widget, for which you can define a maximum width:

QWidget *controlsRestrictorWidget = new QWidget();
QVBoxLayout *layoutVControls = new QVBoxLayout();
controlsRestrictorWidget->setLayout(layoutVControls);
controlsRestrictorWidget->setMaximumWidth(350);

It works :)

like image 102
SomethingSomething Avatar answered Oct 15 '22 16:10

SomethingSomething