The ToolBar basis

The ToolBar is introduced

Header file: #include

Qmake: QT + = widgets

Inherits from: QWidget

Tool bar, I believe you are not unfamiliar, this article to tell you how to use the tool bar, and how to work with the previously mentioned ToolButton. ! [insert picture description here] (img – blog. Csdnimg. Cn / 20210128194… =400x)


Movable property

This property is used to determine if the toolBar can be moved. Notice in the diagram above, there is a lot of little dots on the far left of the toolBar. If you uncheck this property, the dots will not exist, and of course, your toolBar will not be moved.

This property defaults to true.

UI Settings:This property can be accessed and set by code via isMovable() and setMovable().


AllowedAreas property

This property specifies the range in which the toolbar is allowed to move. The default value is AllToolBarAreas (all four directions are allowed: window left, right, under the menu, and above the bottom status bar).

The other five values are left and right of the window, under the menu, above the status bar at the bottom, and NoToolBarArea (NoToolBarArea is set, meaning you can put it anywhere).

UI Settings:Code can access and set this variable through allowedAreas() and setAllowedAreas.


Orientation attribute

This property is the orientation of the toolbar, which defaults to Qt :: Horizontal.

Note: This feature should not be used when the toolbar is managed by QMainWindow. If you want to move the toolbar already added to the main window to another Qt :: ToolBarArea, you can use QMainWindow :: addToolBar () or QMainWindow :: insertToolBar ().

UI Settings:

Code can access and set this property through orientation() and setOrientation().


IconSize property

This property sets the icon bar, size, and is described in the previous section.


ToolButtonStyle properties

This property specifies the button display mode, which defaults to ToolButtonIconOnly (show ICONS only).

The other four values are: ToolButtonTextOnly (text only)

ToolButtonTextBesideIcon (Text next to icon)

ToolButtonTextUnderIcon (text under icon)

ToolButtonFollowStyle (shows according to QStyle::StyleHint format, we did not set StyleHint, so it is the default)

UI Settings:

Code can access and set this property with toolButtonStyle() and setToolButtonStyle().

This property defines the style of all tool buttons that are added as qActions. Note that if you add QToolButton using the addWidget () method, it will not get this button style.

To make the style of the tool button follow system Settings, set this property to Qt :: ToolButtonFollowStyle.


Floatble properties

This property saves whether the toolbar can be dragged and dropped as a separate window. The default is true.

When set to false, although the mouse can drag the toolbar, it cannot stand alone.

UI Settings:

Code can access and set this property with isFloatable() and setFloatable().


The ToolBar advanced

Add controls to the ToolBar

Start by creating a main window UI with a TooBar by default. Drag four ToolButton buttons across the UI and add ICONS for each button.Now add the code to make the four buttons appear above the toolbar.

// UI -> The toolBar is our toolBar
    ui->toolBar->addWidget(ui->toolButton);
    ui->toolBar->addWidget(ui->toolButton_2);
    ui->toolBar->addWidget(ui->toolButton_3);
    ui->toolBar->addWidget(ui->toolButton_4);
Copy the code

run

For details on how to add a menu to toolButtons, refer to the QT System Learning series:

In addition to adding a widget using addWidget(), you can add a separator using addSeparator(), or add an action using addAction().


Beautify the ToolBar

no