diff --git a/SoftwareDesign/Code/2-2-4/2-2-4.pro b/SoftwareDesign/Code/2-2-4/2-2-4.pro new file mode 100644 index 0000000..9f9e6a5 --- /dev/null +++ b/SoftwareDesign/Code/2-2-4/2-2-4.pro @@ -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 diff --git a/SoftwareDesign/Code/2-2-4/main.cpp b/SoftwareDesign/Code/2-2-4/main.cpp new file mode 100644 index 0000000..4d6c97b --- /dev/null +++ b/SoftwareDesign/Code/2-2-4/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + + return a.exec(); +} diff --git a/SoftwareDesign/Code/2-2-4/widget.cpp b/SoftwareDesign/Code/2-2-4/widget.cpp new file mode 100644 index 0000000..4c01774 --- /dev/null +++ b/SoftwareDesign/Code/2-2-4/widget.cpp @@ -0,0 +1,43 @@ +#include "widget.h" +#include "ui_widget.h" +#include +#include +#include + +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; +} diff --git a/SoftwareDesign/Code/2-2-4/widget.h b/SoftwareDesign/Code/2-2-4/widget.h new file mode 100644 index 0000000..ad4a112 --- /dev/null +++ b/SoftwareDesign/Code/2-2-4/widget.h @@ -0,0 +1,22 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include + +namespace Ui { +class Widget; +} + +class Widget : public QWidget +{ + Q_OBJECT + +public: + explicit Widget(QWidget *parent = 0); + ~Widget(); + +private: + Ui::Widget *ui; +}; + +#endif // WIDGET_H diff --git a/SoftwareDesign/Code/2-2-4/widget.ui b/SoftwareDesign/Code/2-2-4/widget.ui new file mode 100644 index 0000000..e9b99ec --- /dev/null +++ b/SoftwareDesign/Code/2-2-4/widget.ui @@ -0,0 +1,32 @@ + + + Widget + + + + 0 + 0 + 400 + 300 + + + + Widget + + + + + 80 + 140 + 120 + 80 + + + + + + + + + +