[QT]QT教程之实例分析[四]多窗口文档[QWorkspace]时间:2022-09-06 05:30:06重点知识已近在代码里注释...请仔细看代码本文原创转载请保留此链接 http://blog.csdn.net/siren0203 头文件 mainWidget.h #ifndef MAINDWIDGET_H#define MAINDWIDGET_H#include <QMainWindow>#include <QObject>class QWorkspace;class mainWidget:public QMainWindow{ Q_OBJECTpublic: mainWidget(QWidget *parent=0);private : QWorkspace *workSpace;};#endif // MAINDWIDGET_H 实现代码 main.cpp #include <QApplication>#include <QWorkspace>#include <QTextEdit>#include "maindWidget.h"mainWidget::mainWidget(QWidget *parent):QMainWindow(parent){ //创建一个 QWorkspace 对象 workSpace =new QWorkspace(this); //设置主窗体的*窗口为QWorkspace对象 实现窗口多布局方式 setCentralWidget(workSpace); //创建窗口一 QMainWindow *window1=new QMainWindow(this); window1->setWindowTitle(tr("window 1")); QTextEdit *edit1=new QTextEdit(this); edit1->setText("window 1"); window1->setCentralWidget(edit1);//创建窗口2 QMainWindow *window2=new QMainWindow(this); window2->setWindowTitle(tr("window 2")); QTextEdit *edit2=new QTextEdit(this); edit2->setText("window 2"); window2->setCentralWidget(edit2);//创建窗口3 QMainWindow *window3=new QMainWindow(this); window3->setWindowTitle(tr("window 3")); QTextEdit *edit3=new QTextEdit(this); window3->setCentralWidget(edit3);//将子窗口插入到 workSpace中 实现多窗口 workSpace->addWindow(window1); workSpace->addWindow(window2); workSpace->addWindow(window3);}int main(int argc,char **argv){ QApplication app(argc,argv); mainWidget main; main.show(); return app.exec();} 效果图..