This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/SoftwareDesign/Lab2/2-2-4/widget.cpp
2022-04-26 14:51:03 +08:00

43 lines
1.1 KiB
C++

#include "widget.h"
#include "ui_widget.h"
#include <QStackedLayout>
#include <QListWidget>
#include <QLabel>
Widget::Widget(QWidget *parent) :
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(widget3);
QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->addWidget(listWidget);
hLayout->addLayout(sLayout);
setLayout(hLayout);
QObject::connect(listWidget, &QListWidget::currentRowChanged, sLayout, &QStackedLayout::setCurrentIndex);
}
Widget::~Widget()
{
delete ui;
}