Qt-多文档界面应用

Qt-多文档界面应用_第1张图片

mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include 
#include
#include
#include
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
private:
    Ui::MainWindow *ui;
    QMdiArea * m_mdiArea;
private slots:
    void actNewWindow();
 
};
 
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
 
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
 
    ui->setupUi(this);
    m_mdiArea = new QMdiArea;
    this->setCentralWidget(m_mdiArea);
 connect(ui->actionNew,SIGNAL(triggered()),this,SLOT(actNewWindow()));
 
}
void MainWindow::actNewWindow()
{
    QLabel *label = new QLabel(tr("MDI SubWindow"));
    QMdiSubWindow *subwin = new QMdiSubWindow;
    subwin->setWidget(label);
    subwin->setAttribute(Qt::WA_DeleteOnClose);
 subwin->resize(180,100);
m_mdiArea->addSubWindow(subwin);
subwin->show();
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 

你可能感兴趣的:(QT图形化界面,QT图形化界面设计)