```c++
#include "widget.h"
#include "ui_widget.h"
#include "QListWidget"
#include "QWidget"
#include "QStackedLayout"
Widget::Widget(QWidget *parent) :
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/290091436636151.png "#left")
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QListWidget *listWidget = new QListWidget();
listWidget->addItem("One");
listWidget->addItem("Two");
listWidget->addItem("Three");
QWidget *widget1 = new Qwidget();
QWidget *widget2 = new Qwidget();
QWidget *widget3 = new Qwidget();
QLabel *label1 = new Qlabel("LABEL ONE", widget1);
QLabel *label2 = new Qlabel("LABEL TWO", widget2);
QLabel *label3 = new Qlabel("LABEL THREE", widget3);
QStackedLayout *sLayout = new QStackedLayout();
sLayout->addWidget(widget1);
sLayout->addWidget(widget2);
sLayout->addWidget(sLayout);
QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->addWidget(listWidget);
hLayout->addLayout(sLayout);
setLayout(hLayout);
QObject::connect(listWidget, &QListWidget::currentRowChanged, sLayout, &QStackedLayout::setCurrentIndex);
}
Widget::~Widget()
{
delete ui;
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/051691436636155.png "#left")