QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(new QLabel("Label 1")); layout->addWidget(new QLabel("Label 2")); layout->addWidget(new QLabel("Label 3")); QLayoutItem *item = layout->takeAt(1); delete item;
QHBoxLayout *layout1 = new QHBoxLayout; layout1->addWidget(new QLabel("Label 4")); layout1->addWidget(new QLabel("Label 5")); QHBoxLayout *layout2 = new QHBoxLayout; layout2->addWidget(new QLabel("Label 6")); layout2->addWidget(new QLabel("Label 7")); QVBoxLayout *layout = new QVBoxLayout; layout->addLayout(layout1); layout->addStretch(); layout->addLayout(layout2); QLayoutItem *item = layout->takeAt(1); delete item;In this example, a QVBoxLayout is created, and two QHBoxLayouts are added to it along with a stretch function. The takeAt function is used to remove the stretch function from the layout and delete it. This code is written in C++ using the Qt framework, specifically the QLayout class, which is part of the Qt widgets module.