1. 程式人生 > >Qt之多文件介面(QMdiArea QMdiSubWindow)

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(); }

效果:
這裡寫圖片描述