Qt之多文档界面(QMdiArea QMdiSubWindow)

public slots:
    void is_clicked();
private:
    QMdiArea *ma;
#include "mainwindow.h"
#include <QMenu>
#include <QMenuBar>
#include <QTextEdit>
#include <QMdiSubWindow>
#include <QMdiArea>
#include <QWidget>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    resize(600,600);
    QMenu *me = menuBar()->addMenu(tr("文件"));
    QAction *open = new QAction(tr("新建"));
    me->addAction(open);
    ma = new QMdiArea;
    this->setCentralWidget(ma);
    connect(open,&QAction::triggered,this,&MainWindow::is_clicked);

}
void MainWindow::is_clicked()
{
    QTextEdit *td = new QTextEdit(this);
    td->resize(200,200);
    QMdiSubWindow *child = ma->addSubWindow(td);
    child->resize(300,300);
    child->show();
}

效果:
Qt之多文档界面(QMdiArea QMdiSubWindow)_第1张图片

你可能感兴趣的:(Qt)