标签:
#include "mainwindow.h"
#include <QDockWidget>
#include <QTextEdit>
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle(tr("Dock Windows"));
QTextEdit *edt = new QTextEdit(tr("Main Window"),this);
setCentralWidget(edt); //把edt设置为中心控件
//停靠窗口1:
QDockWidget *dockWidget1 = new QDockWidget(tr("Dock Window 1"),this);
dockWidget1->setFeatures(QDockWidget::DockWidgetMovable);
dockWidget1->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
QTextEdit *edt1 = new QTextEdit(tr("Window 1"));
dockWidget1->setWidget(edt1);
addDockWidget(Qt::RightDockWidgetArea,dockWidget1);
//停靠窗口2:
QDockWidget *dockWidget2 = new QDockWidget(tr("Dock Window 2"),this);
dockWidget2->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
QTextEdit *edt2 = new QTextEdit(tr("Window 2"));
dockWidget2->setWidget(edt2);
addDockWidget(Qt::LeftDockWidgetArea,dockWidget2);
//停靠窗口3:
QDockWidget *dockWidget3 = new QDockWidget(tr("Dock Window 3"),this);
dockWidget3->setFeatures(QDockWidget::AllDockWidgetFeatures);
QTextEdit *edt3 = new QTextEdit(tr("Window 3"));
dockWidget3->setWidget(edt3);
addDockWidget(Qt::BottomDockWidgetArea,dockWidget3);
}
MainWindow::~MainWindow()
{
delete ui;
}
标签:
原文地址:http://www.cnblogs.com/dongdongweiwu/p/4325620.html