照搬
This commit is contained in:
parent
cd38a5a362
commit
74e693590a
5 changed files with 137 additions and 0 deletions
29
SoftwareDesign/Code/2-2-4/2-2-4.pro
Normal file
29
SoftwareDesign/Code/2-2-4/2-2-4.pro
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = 2-2-4
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
widget.cpp
|
||||
|
||||
HEADERS += \
|
||||
widget.h
|
||||
|
||||
FORMS += \
|
||||
widget.ui
|
11
SoftwareDesign/Code/2-2-4/main.cpp
Normal file
11
SoftwareDesign/Code/2-2-4/main.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Widget w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
43
SoftwareDesign/Code/2-2-4/widget.cpp
Normal file
43
SoftwareDesign/Code/2-2-4/widget.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#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;
|
||||
}
|
22
SoftwareDesign/Code/2-2-4/widget.h
Normal file
22
SoftwareDesign/Code/2-2-4/widget.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class Widget;
|
||||
}
|
||||
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Widget(QWidget *parent = 0);
|
||||
~Widget();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
};
|
||||
|
||||
#endif // WIDGET_H
|
32
SoftwareDesign/Code/2-2-4/widget.ui
Normal file
32
SoftwareDesign/Code/2-2-4/widget.ui
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Widget</class>
|
||||
<widget class="QWidget" name="Widget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Widget</string>
|
||||
</property>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>140</y>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QWidget" name="page"/>
|
||||
<widget class="QWidget" name="page_2"/>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Reference in a new issue