Table of contents
4. Floating window/riveted parts
5. Central Parts/Central Controls
1. Menu bar
<QMenuBar>
<QMenu>
only one
1. Create the menu bar
QMenuBar* bar = new QMenuBar(this);
2. Put the menu into the main window
this->setMenuBar(bar);
3. Create a menu
QMenu* start = bar->addMenu("start");
4. Add menu items
start->addAction("save");
5. Add dividers
start->addSeparator();
2. Toolbar
<QToolBar>
can have multiple
1. Create and add a toolbar, and initialize the docking position to the left
QToolBar* tool = new QToolBar(this);
this->addToolBar(Qt::LeftToolBarArea, tool);
2. Add tool items, you can add controls
tool->addAction("search");
QPushButton* but = new QPushButton("save", this);
tool->addWidget(but);//添加按钮控件
3. Select the mobile attribute (whether it can be moved), the default is mobile
tool->setMovable(false);//不能移动
4. Select the floating property (whether it must be docked), the default is floating
tool->setFloatable(false);//禁止浮动
5. Select the subsequent docking status
//允许左右停靠
tool->setAllowedAreas(Qt::LeftToolBarArea|Qt::RightToolBarArea);
3. Status bar
<QStatusBar>
only one
1. Create and add a status bar
QStatusBar* status = new QStatusBar(this);
this->setStatusBar(status);
2. Add controls, default on the left
QPushButton* but = new QPushButton("save", this);
status->addWidget(but);
Note: addAction does not report an error when adding an action class, but it is invalid
3. Add controls from the right
QLabel * lab = new QLabel("status", this);
status->addPermanentWidget(lab);//添加标签控件
4. Floating window/riveted parts
<QDockWidget>
can have multiple
1. To create and add a floating window, an initialization position needs to be given
QDockWidget* dock = new QDockWidget("Dock", this);
addDockWidget(Qt::BottomDockWidgetArea, dock);//底部
2. Select the floating method, the default floating
dock->setFloating(true);
3. Select a docking location
dock->setAllowedAreas(Qt::AllDockWidgetAreas);//全方位停靠
4. Add controls
QPushButton* but = new QPushButton("save", this);
dock->setWidget(but);
5. Set the window size
dock->resize(200, 50);
5. Central Parts/Central Controls
Take notepad as an example
<QTextEdit>
1. Create a Notepad control
QTextEdit* text = new QTextEdit(this);
2. Add a center control
setCentralWidget(text);