当前位置:网站首页>QT learning diary 7 - qmainwindow
QT learning diary 7 - qmainwindow
2022-07-02 11:04:00 【herb. dr】
Catalog
One 、QMainWindow brief introduction
One 、QMainWindow brief introduction
1.1 written words
QMainWindow Is a class that provides the main window program for users , Contains a menu bar (menu bar)、 Multiple toolbars (tool bars)、 Multiple anchoring components (dock widgets)、 A status bar (status bar) And a central part (central widget), Is the foundation of many applications , Like a text editor , Picture editor, etc
1.2 Icon

Two 、 Create interface
2.1 choice QMainWindow


2.2 Create menu bar
1、 Create a menu bar without throwing it on the screen

2、 Put the menu bar in the window , And create a menu
There can be at most one menu bar

#include "mainwindow.h"
#include <QMenuBar>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Reset window size
resize(600, 400);
// Menu bar create
QMenuBar *bar = menuBar();
// Put the menu bar in the window
setMenuBar(bar);
// Create a menu
QMenu* fileMenu = bar->addMenu(" file ");
QMenu* editMenu = bar->addMenu(" edit ");
}
MainWindow::~MainWindow()
{
}3、 Create menu items

4、 Add separator

2.3 Create toolbars
1、 Default generation
#include "mainwindow.h"
#include <QMenuBar>
#include <QToolBar>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Reset window size
resize(600, 400);
// Menu bar create
QMenuBar *bar = menuBar();
// Put the menu bar in the window
setMenuBar(bar);
// Create a menu
QMenu* fileMenu = bar->addMenu(" file ");
QMenu* editMenu = bar->addMenu(" edit ");
fileMenu->addAction(" newly build ");
fileMenu->addSeparator();
fileMenu->addAction(" open ");
QToolBar* toolBar = new QToolBar(this);
addToolBar(toolBar);
}
MainWindow::~MainWindow()
{
}
2、 Generate on the left
You can check the documentation about other parameters of this function

3、 Only left and right stops are allowed

4、 Floating is not allowed

5、 Mobile main switch
Turn off this switch , The above settings are meaningless
toolBar->setMovable(false);
6、 Set the content in the toolbar

#include "mainwindow.h"
#include <QMenuBar>
#include <QToolBar>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Reset window size
resize(600, 400);
// Menu bar create
QMenuBar *bar = menuBar();
// Put the menu bar in the window
setMenuBar(bar);
// Create a menu
QMenu* fileMenu = bar->addMenu(" file ");
QMenu* editMenu = bar->addMenu(" edit ");
QAction* newAction = fileMenu->addAction(" newly build ");
fileMenu->addSeparator();
QAction* openAction = fileMenu->addAction(" open ");
QToolBar* toolBar = new QToolBar(this);
addToolBar(Qt::LeftToolBarArea, toolBar);
// Only Left and right docking
toolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea );
toolBar->setFloatable(false);
toolBar->addAction(newAction);
toolBar->addAction(openAction);
}
MainWindow::~MainWindow()
{
}
Add separation lines

7、 Add controls to the toolbar

2.4 status bar
1、 status bar
There can be at most one
#include "mainwindow.h"
#include <QMenuBar>
#include <QToolBar>
#include <QDebug>
#include <QPushButton>
#include <QStatusBar>
#include <QLabel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Reset window size
resize(600, 400);
// Menu bar create
QMenuBar *bar = menuBar();
// Put the menu bar in the window
setMenuBar(bar);
// Create a menu
QMenu* fileMenu = bar->addMenu(" file ");
QMenu* editMenu = bar->addMenu(" edit ");
QAction* newAction = fileMenu->addAction(" newly build ");
fileMenu->addSeparator();
QAction* openAction = fileMenu->addAction(" open ");
QToolBar* toolBar = new QToolBar(this);
addToolBar(Qt::LeftToolBarArea, toolBar);
// Only Left and right docking
toolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea );
toolBar->setFloatable(false);
toolBar->addAction(newAction);
toolBar->addSeparator();
toolBar->addAction(openAction);
QPushButton* btn = new QPushButton("aa", this);
toolBar->addWidget(btn);
// status bar There is at most one
QStatusBar* stBar = statusBar();
// Set to the window
setStatusBar(stBar);
// Create a label control
QLabel* label = new QLabel(" Prompt information ", this);
// Put the label control in the status bar
stBar->addWidget(label);
}

2、 Prompt message on the right
2.5 Riveted parts
Header file #include <QDockWidget>

Set the post docking area , Only up and down allowed

2.6 Set the center part
You can only set one
Add header file #include <QTextEdit>

边栏推荐
- 【快应用】Win7系统使用华为IDE无法运行和调试项目
- 【AGC】构建服务3-认证服务示例
- MySQL environment configuration
- MySQL lethal serial question 3 -- are you familiar with MySQL locks?
- PCL eigen introduction and simple use
- UVM factory mechanism
- 【ARK UI】HarmonyOS ETS的启动页的实现
- Huawei game failed to initialize init with error code 907135000
- 洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
- PCL 投影点云
猜你喜欢

JSP webshell free -- webshell free
![二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)

HDU1236 排名(结构体排序)

VSCode工具使用

How to transfer event objects and user-defined parameters simultaneously in Huawei express applications

Open the encrypted SQLite method with sqlcipher

二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
![[in simple terms, play with FPGA learning 3 ----- basic grammar]](/img/f0/0204fa5197033877dc0758203253ae.png)
[in simple terms, play with FPGA learning 3 ----- basic grammar]
![[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)](/img/9f/4265f1e3927fcf66602f0fc9e7a9d9.jpg)
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)

flink二開,實現了個 batch lookup join(附源碼)
随机推荐
Hdu1234 door opener and door closer (water question)
[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched
Hdu1228 a + B (map mapping)
flink二开,实现了个 batch lookup join(附源码)
[AI application] Hikvision ivms-4200 software installation
【深入浅出玩转FPGA学习5-----复位设计】
首份中国企业敏捷实践白皮书发布| 附完整下载
2022爱分析· 国央企数字化厂商全景报告
Kustomize user manual
Open the encrypted SQLite method with sqlcipher
Huawei game failed to initialize init with error code 907135000
Filtering of PCL
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
一招快速实现自定义快应用titlebar
华为游戏初始化init失败,返回错误码907135000
如何用list组件实现tabbar标题栏
One trick to quickly realize custom application titlebar
JSP webshell free -- the basis of JSP
【深入浅出玩转FPGA学习4----漫谈状态机设计】
Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)