//dockwindows.h
#pragma once
#include <QtGui>
class DockWindows : public QMainWindow
{
Q_OBJECT
public:
DockWindows();
~DockWindows();
};
//dockwindows.cpp
#include "dockwindows.h"
DockWindows::DockWindows(): QMainWindow()
{
setWindowTitle( tr( "DockWindows" ) );
QTextEdit *te = new QTextEdit( this );
te->setText(tr("Main Window"));
te->setAlignment(Qt::AlignCenter);
//te->setMinimumWidth(640);
//this->resize(800,600);
setCentralWidget( te );
// 停靠窗口 1
QDockWidget *dock = new QDockWidget(tr("DockWindow 1"), this );
dock->setFeatures(QDockWidget::DockWidgetFeature::AllDockWidgetFeatures);
//same as dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
dock->setAllowedAreas(Qt::DockWidgetArea::AllDockWidgetAreas);
//same as dock->setAllowedAreas(Qt::AllDockWidgetAreas);
QTextEdit *te1 = new QTextEdit();
te1->setText(tr("Window 1"));
dock->setWidget( te1 );
addDockWidget( Qt::RightDockWidgetArea, dock );
// 停靠窗口 2
dock = new QDockWidget( tr("DockWindow 2"), this );
//dock->setFeatures( QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetClosable);
QTextEdit *te2 = new QTextEdit();
te2->setText(tr("Window 2"));
dock->setWidget( te2 );
addDockWidget( Qt::RightDockWidgetArea, dock);
// 停靠窗口 3
dock = new QDockWidget( tr("DockWindow 3"),this );
dock->setFeatures( QDockWidget::AllDockWidgetFeatures );
QTextEdit *te3 = new QTextEdit();
te3->setText(tr("Window 3"));
dock->setWidget( te3 );
addDockWidget( Qt::BottomDockWidgetArea, dock);
}
DockWindows::~DockWindows()
{
}
//main.cpp
#include "dockwindows.h"
#include <QApplication>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QTranslator translator(0);
translator.load("dockwindows_zh",".");
a.installTranslator(&translator);
DockWindows *dockwindows = new DockWindows();
dockwindows->show();
return a.exec();
}