QToolBar Class

The QToolBar class provides a movable panel that contains a set of controls. More...

Header: #include <QToolBar>
qmake: QT += widgets
Inherits: QWidget

Properties

Public Functions

Qt::ToolBarAreas allowedAreas() const
QSize iconSize() const
bool isFloatable() const
bool isFloating() const
bool isMovable() const
Qt::Orientation orientation() const
void setAllowedAreas(Qt::ToolBarAreas areas)
void setFloatable(bool floatable)
void setMovable(bool movable)
void setOrientation(Qt::Orientation orientation)
Qt::ToolButtonStyle toolButtonStyle() const

Public Slots

void setIconSize(const QSize &iconSize)
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)

Signals

void allowedAreasChanged(Qt::ToolBarAreas allowedAreas)
void iconSizeChanged(const QSize &iconSize)
void movableChanged(bool movable)
void orientationChanged(Qt::Orientation orientation)
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)

Detailed Description

Toolbar buttons are added by adding actions, using addAction() or insertAction(). Groups of buttons can be separated using addSeparator() or insertSeparator(). If a toolbar button is not appropriate, a widget can be inserted instead using addWidget() or insertWidget(). Examples of suitable widgets are QSpinBox, QDoubleSpinBox, and QComboBox. When a toolbar button is pressed, it emits the actionTriggered() signal.

A toolbar can be fixed in place in a particular area (e.g., at the top of the window), or it can be movable between toolbar areas; see setMovable(), isMovable(), allowedAreas() and isAreaAllowed().

When a toolbar is resized in such a way that it is too small to show all the items it contains, an extension button will appear as the last item in the toolbar. Pressing the extension button will pop up a menu containing the items that do not currently fit in the toolbar.

When a QToolBar is not a child of a QMainWindow, it loses the ability to populate the extension pop up with widgets added to the toolbar using addWidget(). Please use widget actions created by inheriting QWidgetAction and implementing QWidgetAction::createWidget() instead.

See also QToolButton, QMenu, QAction, and Application Example.

Property Documentation

allowedAreas : Qt::ToolBarAreas

areas where the toolbar may be placed

The default is Qt::AllToolBarAreas.

This property only makes sense if the toolbar is in a QMainWindow.

Access functions:

Qt::ToolBarAreas allowedAreas() const
void setAllowedAreas(Qt::ToolBarAreas areas)

Notifier signal:

void allowedAreasChanged(Qt::ToolBarAreas allowedAreas)

See also movable.

floatable : bool

This property holds whether the toolbar can be dragged and dropped as an independent window.

The default is true.

Access functions:

bool isFloatable() const
void setFloatable(bool floatable)

floating : const bool

This property holds whether the toolbar is an independent window.

By default, this property is true.

Access functions:

bool isFloating() const

See also QWidget::isWindow().

iconSize : QSize

size of icons in the toolbar.

The default size is determined by the application's style and is derived from the QStyle::PM_ToolBarIconSize pixel metric. It is the maximum size an icon can have. Icons of smaller size will not be scaled up.

Access functions:

QSize iconSize() const
void setIconSize(const QSize &iconSize)

Notifier signal:

void iconSizeChanged(const QSize &iconSize)

movable : bool

This property holds whether the user can move the toolbar within the toolbar area, or between toolbar areas.

By default, this property is true.

This property only makes sense if the toolbar is in a QMainWindow.

Access functions:

bool isMovable() const
void setMovable(bool movable)

Notifier signal:

void movableChanged(bool movable)

See also allowedAreas.

orientation : Qt::Orientation

orientation of the toolbar

The default is Qt::Horizontal.

This function should not be used when the toolbar is managed by QMainWindow. You can use QMainWindow::addToolBar() or QMainWindow::insertToolBar() if you wish to move a toolbar that is already added to a main window to another Qt::ToolBarArea.

Access functions:

Qt::Orientation orientation() const
void setOrientation(Qt::Orientation orientation)

Notifier signal:

void orientationChanged(Qt::Orientation orientation)

toolButtonStyle : Qt::ToolButtonStyle

This property holds the style of toolbar buttons

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

To have the style of toolbuttons follow the system settings, set this property to Qt::ToolButtonFollowStyle. On Unix, the user settings from the desktop environment will be used. On other platforms, Qt::ToolButtonFollowStyle means icon only.

The default is Qt::ToolButtonIconOnly.

Access functions:

Qt::ToolButtonStyle toolButtonStyle() const
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)

Notifier signal:

void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)