#include "mainwindow.h" #include <QMenu> #include <QMenuBar> #include <QAction> #include <QToolBar> #include <QStatusBar> #include <QPushButton> #include <QTextEdit> #include <QDockWidget> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // meun QMenuBar *mbar = menuBar(); QMenu *pFile = mbar->addMenu("File"); QAction *pNew = pFile->addAction("New File"); QAction *pOpen = pFile->addAction("Open File"); pFile->addSeparator(); // add separator QAction *pRecentFile = pFile->addAction("Recent File"); //connect(pNew, &QAction::triggered, this, &QMainWindow::close); // tool QToolBar *toolBar = addToolBar("toolBar"); toolBar->addAction(pNew); QPushButton *bOpenFile = new QPushButton(this); bOpenFile->setText("Open File"); toolBar->addWidget(bOpenFile); // Status QStatusBar *pStatuesBar = statusBar(); QLabel *plabel = new QLabel(this); plabel->setText("Normal text file"); pStatuesBar->addWidget(plabel); // TextEdit QTextEdit *textEdit = new QTextEdit(this); setCentralWidget(textEdit); // Dock window QDockWidget *dockW = new QDockWidget(this); addDockWidget(Qt::RightDockWidgetArea, dockW); QTextEdit *textEditDockW = new QTextEdit(this); dockW->setWidget(textEditDockW); } MainWindow::~MainWindow() { }
原文:https://www.cnblogs.com/JokerXp/p/15126017.html