1、添加子类
效果如下: subtext.cpp
#include "subtext.h"
subText::subText(QWidget *parent) : QTextEdit(parent)
{
}
subtext.h
#ifndef SUBTEXT_H
#define SUBTEXT_H
#include <QWidget>
#include <QTextEdit>
class subText : public QTextEdit
{
Q_OBJECT
public:
explicit subText(QWidget *parent = nullptr);
signals:
public slots:
};
#endif
2、添加MID Area容器
目的是将新建的text框显示在此容器里
3、功能显示
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFont font;
font.setBold(true);
font.setStyle(QFont::StyleOblique);
ui->action_New->setFont(font);
Init();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::Init(){
connect(ui->action_New,SIGNAL(triggered(bool)),
this,SLOT(doProcessTriggeredByNew(bool)));
}
void MainWindow::doProcessTriggeredByNew(bool){
qDebug()<<"triggered New action"<<endl;
subText *sub = new subText();
ui->mdiArea->addSubWindow(sub);
sub->show();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <subtext.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void doProcessTriggeredByNew(bool);
private:
Ui::MainWindow *ui;
void Init();
};
#endif
4、最终效果
|