stackdlg.h
#ifndef STACKDLG_H #define STACKDLG_H #include <QtWidgets/QDialog> #include <QListWidget> #include <QStackedWidget> #include <QLabel> #include "ui_stackdlg.h" class StackDlg : public QDialog { Q_OBJECT public: StackDlg(QWidget *parent = 0); ~StackDlg(); private: Ui::StackDlgClass ui; QListWidget *list; QStackedWidget *stack; QLabel *label1; QLabel *label2; QLabel *label3; }; #endif // STACKDLG_H
stackdlg.cpp
#include "stackdlg.h" #include <QHBoxLayout> StackDlg::StackDlg(QWidget *parent) : QDialog(parent) { ui.setupUi(this); setWindowTitle("StackWidget"); list = new QListWidget(this); list->insertItem(0, "windows1"); list->insertItem(1, "windows2"); list->insertItem(2, "windows3"); label1 = new QLabel("label1"); label2 = new QLabel("label2"); label3 = new QLabel("label3"); stack = new QStackedWidget(this); stack->addWidget(label1); stack->addWidget(label2); stack->addWidget(label3); QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setMargin(5); mainLayout->setSpacing(5); mainLayout->addWidget(list); mainLayout->addWidget(stack, 0, Qt::AlignHCenter); mainLayout->setStretchFactor(list, 1); mainLayout->setStretchFactor(stack, 3); connect(list, SIGNAL(currentRowChanged(int)), stack, SLOT(setCurrentIndex(int))); } StackDlg::~StackDlg() { }
qdock.cpp
#include "qdock.h" #include <QTextEdit> #include <QDockWidget> Qdock::Qdock(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); setWindowTitle("Test"); QTextEdit *te = new QTextEdit(this); te->setText("Main Window"); te->setAlignment(Qt::AlignCenter); setCentralWidget(te); QDockWidget *dock = new QDockWidget("Dock Window1", this); dock->setFeatures(QDockWidget::DockWidgetMovable); dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); QTextEdit *te1 = new QTextEdit; te1->setText("Dock Window1"); dock->setWidget(te1); addDockWidget(Qt::RightDockWidgetArea, dock); dock = new QDockWidget("Dock Window2", this); dock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable); QTextEdit *te2 = new QTextEdit; te2->setText("Dock Window2"); dock->setWidget(te2); addDockWidget(Qt::RightDockWidgetArea, dock); dock = new QDockWidget("Dock Window3", this); dock->setFeatures(QDockWidget::AllDockWidgetFeatures); QTextEdit *te3 = new QTextEdit; te3->setText("Dock Windo3"); dock->setWidget(te3); addDockWidget(Qt::RightDockWidgetArea, dock); } Qdock::~Qdock() { }