qt学习——QMainWindow

一、QMainWindow.h

1.1菜单栏(最多只有一个)

QMenuBar *bar = menuBar();                                                                                       //菜单栏创建

setMenuBar(bar);                                                                                                       //将菜单栏放入窗口

 

QMenu *fileMenu = bar->addMenu("文件");                                                              //创建菜单

QAction * action_new = fileMenu->addAction("新建");                                              //创建菜单项

 

fileMenu->addSeparator();                                                                                          //添加分隔符

1.2工具栏(可以多个)

QToolBar *toolBar = new QToolBar;                                                                            //创建工具栏

 

addToolBar(Qt::LeftToolBarArea,toolBar);                                                                   //窗口添加工具栏,设置初始停靠区域

toolBar->setAllowedAreas(Qt::LeftToolBarArea|Qt::RightToolBarArea);                   //设置允许停靠区域

toolBar->setFloatable(false);                                                                                       //设置浮动

toolBar->setMovable(false);                                                                                        //设置移动

 

toolBar->addAction(action_open);                                                                             //设置工具栏内容

toolBar->addWidget(btn);                                                                                                //添加按钮,QPushButton *btn

1.3状态栏(最多只有一个)

QStatusBar *stBar = statusBar();                                                                                                                                                                                                              //创建状态栏

setStatusBar(stBar);                                                                                                                                                                                                                                 //设置状态栏到窗口

 

QLabel * label = new QLabel("提示信息",this);                                                                                                                                                                                         //放标签控件

stBar->addWidget(label);                                                                                                                                                                                                                         //左侧添加标签

stBar->addPermanentWidget(label1);                                                                                     //右侧添加标签

1.4铆接部件(浮动窗口,可以有多个)

QDockWidget * dockWidget =new QDockWidget("浮动",this);                                              //创建铆接部件

addDockWidget(Qt::BottomDockWidgetArea,dockWidget);                                                   //添加部件到窗口   

dockWidget->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);        //设置后期停靠区域

 

QTextEdit *text = new QTextEdit(this);                                                

setCentralWidget(text);                                                                                                          //设置中心部件

 

注:1.只能有一个的部件设置到窗口时用set(ex:setStatusBar())

       2.可以有多个的部件设置到窗口时用add(ex:addDockWidget())

 

 

上一篇:Java 8 - 收集器Collectors_归约和汇总


下一篇:django与layui的结合尝试5:权限管理(1)