#include "mainwindow.h"
#include<QMenu>
#include<QMenuBar>
#include<QAction>
#include<QDebug>
#include<QToolBar>
#include<QPushButton>
#include<QStatusBar>
#include<QLabel>
#include<QTextEdit>
#include<QDockWidget>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//this->setWindowTitle("TEST");
this->resize(500,500);
//菜单栏////////////////////
QMenuBar *mBar = menuBar();
//添加菜单
QMenu *pFile = mBar->addMenu(QStringLiteral("文件"));
//添加菜单项,即菜单下面的动作
QAction *pNew = pFile->addAction(QStringLiteral("新建"));
connect(pNew,&QAction::triggered,
[=]()
{
qDebug()<<QStringLiteral("“新建”被按下");
}
);
pFile->addSeparator(); //添加分割线
QAction *pOpen = pFile->addAction(QStringLiteral("打开"));
//工具栏/////////////////,通常都是菜单栏里一些常用的操作
QToolBar *toolBar = addToolBar("toolBar");
toolBar->addAction(pNew);//“新建”存在于工具栏
QPushButton *b = new QPushButton(this);
b->setText(QStringLiteral("打开"));
toolBar->addWidget(b);//“打开”以按钮的形式存在于工具栏
connect(b,&QPushButton::clicked,[=](){b->setText("OPEN");});
//状态栏////////////////////
QStatusBar *sBar=statusBar();
QLabel *label = new QLabel(this);
label->setText(QStringLiteral("状态1"));
//addWidget从左往右添加
sBar->addWidget(label);
sBar->addWidget(new QLabel(QStringLiteral("状态2"),this));
//addPermanentWidget从右往左添加
sBar->addPermanentWidget(new QLabel(QStringLiteral("状态3"),this));
sBar->addPermanentWidget(new QLabel(QStringLiteral("状态4"),this));
//核心控件///////////////////////////////
QTextEdit *textE = new QTextEdit(this);
setCentralWidget(textE);
//浮动窗口
QDockWidget *dockW = new QDockWidget(this);
addDockWidget(Qt::LeftDockWidgetArea,dockW);
QTextEdit *textE2 = new QTextEdit(this);
dockW->setWidget(textE2);
}
MainWindow::~MainWindow()
{
}