//dockmainwindow.cpp
#include "dockmainwindow.h"
#include "ui_dockmainwindow.h"
#include <QTextEdit>
#include <QDockWidget>
DockMainWindow::DockMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::DockMainWindow)
{
ui->setupUi(this);
setWindowTitle(tr("DockWindows"));//设置主窗口的标题栏文字
QTextEdit *te=new QTextEdit(this); //定义一个QTextEdit对象作为主窗口
te->setText(tr("Main Windows"));
te->setAlignment(Qt::AlignCenter);
setCentralWidget(te);//将此编辑框设为主窗口的中央窗体
//停靠窗口
QDockWidget *dock=new QDockWidget(tr("DockWindow1"),this);
dock->setFeatures(QDockWidget::DockWidgetMovable);//可移动
//设置停靠窗体可停靠的区域
dock->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
QTextEdit* te1=new QTextEdit();
te1->setText(tr("Window1,the dock widget can be moved between docks by the user"));
dock->setWidget(te1);
addDockWidget(Qt::RightDockWidgetArea,dock);
//停靠窗口二
dock=new QDockWidget(tr("DockWindow2"),this);
dock->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetFloatable);//可关闭,双击窗口可浮动
QTextEdit* te2=new QTextEdit();
te2->setText(tr("Window2,..."));
dock->setWidget(te2);
addDockWidget(Qt::RightDockWidgetArea,dock);
//停靠窗口三
dock=new QDockWidget(tr("DockWindow3"),this);
dock->setFeatures(QDockWidget::AllDockWidgetFeatures);//可关闭,可浮动,可移动
QTextEdit* te3=new QTextEdit();
te2->setText(tr("Window2,The dock widget can be closed,moved,floated"));
dock->setWidget(te3);
addDockWidget(Qt::RightDockWidgetArea,dock);
}
DockMainWindow::~DockMainWindow()
{
delete ui;
}
Qt 停靠窗口QDockWidget类
最新推荐文章于 2023-06-11 10:14:59 发布