Qt-UI
Widgets and Layouts
← GUI Concept | ● | Layout Policies →
For a widget to contain children the widget needs to own a so called layout (QLayout).
The layout contains a list of widget children that are owned by the layout. The layout also has settings and policies how how to layout the owned widgets within the available canvas size, such as the expanding direction and spacing.
Simple Example:
QWidget | QLayout | \ QWidget QWidget
QWidget w;
QLayout *l=new QLayout;
l->setExpandingDirection(Qt:horizontal);
l->setSpacing(100);
l->addWidget(new QWidget);
l->addWidget(new QWidget);
w.setLayout(l);
w.show();
QLayout *l=new QLayout;
l->setExpandingDirection(Qt:horizontal);
l->setSpacing(100);
l->addWidget(new QWidget);
l->addWidget(new QWidget);
w.setLayout(l);
w.show();
Additional helpful layout methods:
- l→itemAt(index) returns the indexed widget from the layout’s widget list
- l→getGeometry() l→setGeometry()
← GUI Concept | ● | Layout Policies →