QVBoxLayout* layout = new QVBoxLayout(); QPushButton* button = new QPushButton("Click me!"); layout->addItem(button); setLayout(layout);
QHBoxLayout* layout = new QHBoxLayout(); QLabel* label = new QLabel("Username:"); QLineEdit* edit = new QLineEdit(); layout->addItem(label); layout->addItem(edit); setLayout(layout);In this example, we create a QHBoxLayout and two widgets: a QLabel and a QLineEdit. Then we add both the widgets to the layout using QLayout addItem method. Finally, we set the layout to the current widget. Both examples use the Qt package library.