QBoxLayout is a class in the Qt framework that provides a layout manager for arranging child widgets horizontally or vertically. The addLayout() function is used to add a nested layout to the current layout.
Example 1: Vertical layout with nested horizontal layouts
QHBoxLayout* hLayout1 = new QHBoxLayout(); QHBoxLayout* hLayout2 = new QHBoxLayout(); QVBoxLayout* vLayout = new QVBoxLayout();
// add widgets to horizontal layout 1 hLayout1->addWidget(widget1); hLayout1->addWidget(widget2);
// add widgets to horizontal layout 2 hLayout2->addWidget(widget3); hLayout2->addWidget(widget4);
// add horizontal layouts to vertical layout vLayout->addLayout(hLayout1); vLayout->addLayout(hLayout2);
This code example creates a main vertical layout and two nested horizontal layouts that are added to it. The widgets are added to the horizontal layouts.
Package library: QtGui
Example 2: Horizontal layout with nested vertical layouts
QVBoxLayout* vLayout1 = new QVBoxLayout(); QVBoxLayout* vLayout2 = new QVBoxLayout(); QHBoxLayout* hLayout = new QHBoxLayout();
// add widgets to vertical layout 1 vLayout1->addWidget(widget1); vLayout1->addWidget(widget2);
// add widgets to vertical layout 2 vLayout2->addWidget(widget3); vLayout2->addWidget(widget4);
// add vertical layouts to horizontal layout hLayout->addLayout(vLayout1); hLayout->addLayout(vLayout2);
This code example creates a main horizontal layout and two nested vertical layouts that are added to it. The widgets are added to the vertical layouts.
Package library: QtGui
C++ (Cpp) QBoxLayout::addLayout - 30 examples found. These are the top rated real world C++ (Cpp) examples of QBoxLayout::addLayout extracted from open source projects. You can rate examples to help us improve the quality of examples.