qt QMainWindow文件中菜单栏,工具栏,状态栏,铆钉,中心控件练习

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include "centerwidget.h"
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setFixedSize(1200,800);
    setWindowTitle("菜单栏");
//    QMenuBar *menubar = this->menuBar();
    QMenuBar *menuBar = new QMenuBar(this);
    this->setMenuBar(menuBar);
    QMenu *filemenu = new QMenu("文件",menuBar);
    menuBar->addMenu((filemenu));
    QMenu *editmenu = new QMenu("编辑",menuBar);
    menuBar->addMenu(editmenu);
    QMenu *runmenu =new QMenu("运行",menuBar);
    menuBar->addMenu(runmenu);
    //添加活动
    QAction *na = new QAction("新建文件或项目",filemenu);
    filemenu->addAction(na);
    QAction *oa = new QAction("打开文件或项目",filemenu);
    filemenu->addAction(oa);
    QAction *bx = new QAction("编写项目",editmenu);
    editmenu->addAction(bx);
    QAction *yx = new QAction("运行项目",runmenu);
    runmenu->addAction(yx);
    /*
       * 工具栏
       * 对应的类:QToolBar
      */
      //创建工具栏
      QToolBar *tbar01 = new QToolBar(this);
      //添加工具类
      this->addToolBar(tbar01);
      //创建活动
      QAction *tAction01 = new QAction("啦啦啦",tbar01);
      //工具栏添加活动
      tbar01->addAction(tAction01);
      QAction *tAction02 = new QAction("德玛西亚",tbar01);
      tbar01->addAction(tAction02);

      QToolBar *tbar02 = new QToolBar(this);
      QAction *tAction03 = new QAction("艾欧尼亚",tbar01);
      tbar02->addAction(tAction03);
      //添加工具栏时指定停靠位置
      this->addToolBar(Qt::RightToolBarArea,tbar02);
      //设置不允许拖拽改变其停靠位置
      tbar01->setMovable(false);

      /*
          QStatusBar:状态栏
      */
      //创建状态栏
      QStatusBar * sBar = new QStatusBar(this);
      //设置状态栏
      this->setStatusBar(sBar);
      QPushButton *btn01 =new QPushButton("按钮1",sBar);
      QPushButton *btn02 =new QPushButton("按钮2",sBar);
      QPushButton *btn03 =new QPushButton("按钮3",sBar);

      sBar->addWidget(btn01);
      sBar->addWidget(btn02);
      sBar->addPermanentWidget(btn03);

      /*
          QDockWidget:铆钉部件
      */
      QDockWidget * dWidget = new QDockWidget("铆钉01",this);
      this->addDockWidget(Qt::LeftDockWidgetArea,dWidget);
      QAction *action11 = new QAction("铆钉中的内容",dWidget);
      dWidget->addAction(action11);

      //中心控件
      //QPushButton *btn04 = new QPushButton("中心控件",this);
      //设置中心控件
      //参数QWidget
      //this->setCentralWidget(btn04);
//      CenterWidget *c = new CenterWidget(this);
//      this->setCentralWidget(c);

}

MainWindow::~MainWindow()
{
    delete ui;
}

你可能感兴趣的:(qt,qt,命令模式,开发语言)