6.0.0-rc4Source

QToolBar Class

The QToolBar class provides a bar of buttons for actions. More…

Header#include <QToolBar>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Functions

QToolBar(const QString &title, QWidget *parent = nullptr)
QToolBar(QWidget *parent = nullptr)
~QToolBar()
voidsetMovable(bool movable)
boolisMovable() const
voidsetAllowedAreas(Qt::ToolBarAreas areas)
Qt::ToolBarAreasallowedAreas() const
boolisAreaAllowed(Qt::ToolBarArea area) const
voidsetOrientation(Qt::Orientation orientation)
Qt::Orientationorientation() const
voidclear()
QAction *addAction(const QString &text)
QAction *addAction(const QString &text, Functor functor)
QAction *addSeparator()
QAction *insertSeparator(QAction *before)
QAction *addWidget(QWidget *widget)
QAction *insertWidget(QAction *before, QWidget *widget)
QRectactionGeometry(QAction *action) const
QAction *actionAt(const QPoint &p) const
QAction *actionAt(int x, int y) const
QAction *toggleViewAction() const
Qt::ToolButtonStyletoolButtonStyle() const
QWidget *widgetForAction(QAction *action) const
boolisFloatable() const
voidsetFloatable(bool floatable)
boolisFloating() const

Reimplemented Public Functions

Public Slots

Signals

voidactionTriggered(QAction *action)
voidmovableChanged(bool movable)
voidallowedAreasChanged(Qt::ToolBarAreas allowedAreas)
voidorientationChanged(Qt::Orientation orientation)
voidtoolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
voidtopLevelChanged(bool topLevel)
voidvisibilityChanged(bool visible)

Reimplemented Protected Functions

voidactionEvent(QActionEvent *event)
voidpaintEvent(QPaintEvent *event)
voidshowEvent(QShowEvent *event)
voidhideEvent(QHideEvent *event)

Detailed Description

A tool bar shows its actions as tool buttons, in a row or a column, usually at the top of a QMainWindow under the menu bar. Add actions, separators and other widgets:

QToolBar *file = window->addToolBar("File");
file->addAction(newAction);
file->addAction(openAction);
file->addSeparator();
file->addWidget(new QComboBox);

Each action gets a QToolButton that follows its text, checked state, enabled state and visibility. A triggered action is reported by actionTriggered(). toggleViewAction() is a checkable action that shows and hides the tool bar, for a menu of the tool bars of a window.

See also QMainWindow, QToolButton and QAction.

Differences from Qt

A tool bar cannot be dragged to another side of the window or float (isFloating() is always false), and it has no extension button for the actions that do not fit. Buttons have no icons, so iconSize() is missing and they show their text whatever the style. A movable tool bar shows a grip that does nothing.

Member Function Documentation

[explicit] QToolBar::QToolBar(const QString &title, QWidget *parent = nullptr)

Constructs a tool bar with the given window title, which names it in toggleViewAction(), and parent.

[explicit] QToolBar::QToolBar(QWidget *parent = nullptr)

Constructs a tool bar with the given parent.

[override] QToolBar::~QToolBar()

Destroys the tool bar.

QAction * QToolBar::actionAt(const QPoint &p) const

Returns the action whose widget is at p, a point in the tool bar, or nullptr.

QAction * QToolBar::actionAt(int x, int y) const

This is an overloaded function.

Returns the action whose widget is at x, y.

[override, protected] void QToolBar::actionEvent(QActionEvent *event)

Reimplements QWidget::actionEvent().

The tool bar makes a button, a separator or a widget for each action, in the order of actions().

QRect QToolBar::actionGeometry(QAction *action) const

Returns the geometry of the widget of action in the tool bar, or an empty rectangle if it has none.

[signal] void QToolBar::actionTriggered(QAction *action)

This signal is emitted when action of the tool bar is triggered.

QAction * QToolBar::addAction(const QString &text)

Creates an action with the given text, adds it to the tool bar and returns it. The tool bar owns the action.

template <typename Functor>QAction * QToolBar::addAction(const QString &text, Functor functor)

This is an overloaded function.

Creates an action with the given text that calls functor when it is triggered, adds it and returns it.

QAction * QToolBar::addSeparator()

Adds a separator after the actions and returns its action.

See also insertSeparator().

QAction * QToolBar::addWidget(QWidget *widget)

Adds widget, such as a combo box, after the actions and returns the action that stands for it. Hiding the action hides the widget. The tool bar takes the widget as a child.

See also insertWidget() and widgetForAction().

Qt::ToolBarAreas QToolBar::allowedAreas() const

Returns the areas of a QMainWindow that the tool bar may go in, Qt::AllToolBarAreas by default.

See also setAllowedAreas().

[signal] void QToolBar::allowedAreasChanged(Qt::ToolBarAreas allowedAreas)

This signal is emitted when the areas the tool bar may go in change to allowedAreas.

void QToolBar::clear()

Removes all the actions of the tool bar.

[override, protected] void QToolBar::hideEvent(QHideEvent *event)

Reimplements QWidget::hideEvent().

QAction * QToolBar::insertSeparator(QAction *before)

Inserts a separator before the action before, or at the end if it is nullptr, and returns its action.

QAction * QToolBar::insertWidget(QAction *before, QWidget *widget)

Inserts widget before the action before, or at the end if it is nullptr, and returns the action that stands for it.

bool QToolBar::isAreaAllowed(Qt::ToolBarArea area) const

Returns whether the tool bar may go in area.

bool QToolBar::isFloatable() const

Returns whether the tool bar may float. The default is true, but tool bars do not float in Nt.

See also setFloatable().

bool QToolBar::isFloating() const

Returns whether the tool bar floats; always false in Nt.

bool QToolBar::isMovable() const

Returns whether the user may move the tool bar. The default is true.

See also setMovable().

[override] QSize QToolBar::minimumSizeHint() const

Reimplements QWidget::minimumSizeHint().

[signal] void QToolBar::movableChanged(bool movable)

This signal is emitted when the tool bar becomes movable or stops being so.

Qt::Orientation QToolBar::orientation() const

Returns whether the buttons are in a row or a column, Qt::Horizontal by default.

See also setOrientation().

[signal] void QToolBar::orientationChanged(Qt::Orientation orientation)

This signal is emitted when the orientation changes to orientation.

[override, protected] void QToolBar::paintEvent(QPaintEvent *event)

Reimplements QWidget::paintEvent().

void QToolBar::setAllowedAreas(Qt::ToolBarAreas areas)

Sets the areas of a QMainWindow that the tool bar may go in to areas.

See also allowedAreas() and isAreaAllowed().

void QToolBar::setFloatable(bool floatable)

Sets whether the tool bar may float to floatable.

void QToolBar::setMovable(bool movable)

Sets whether the user may move the tool bar to movable. A movable tool bar shows a grip at its start.

See also isMovable().

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

Sets whether the buttons are in a row or a column to orientation. QMainWindow sets it from the area the tool bar is in.

See also orientation().

[slot] void QToolBar::setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)

Sets the style of the buttons to toolButtonStyle. A QMainWindow passes its own style on to its tool bars.

See also toolButtonStyle().

[override, protected] void QToolBar::showEvent(QShowEvent *event)

Reimplements QWidget::showEvent().

[override] QSize QToolBar::sizeHint() const

Reimplements QWidget::sizeHint().

QAction * QToolBar::toggleViewAction() const

Returns a checkable action that shows and hides the tool bar, with the window title of the tool bar as its text.

Qt::ToolButtonStyle QToolBar::toolButtonStyle() const

Returns the style of the buttons, Qt::ToolButtonIconOnly by default.

See also setToolButtonStyle().

[signal] void QToolBar::toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)

This signal is emitted when the style of the buttons changes to toolButtonStyle.

[signal] void QToolBar::topLevelChanged(bool topLevel)

This signal is emitted when the tool bar starts or stops floating; topLevel says which. Tool bars do not float in Nt, so it is never emitted.

[signal] void QToolBar::visibilityChanged(bool visible)

This signal is emitted when the tool bar is shown or hidden; visible says which.

QWidget * QToolBar::widgetForAction(QAction *action) const

Returns the widget of action: its tool button, the widget given to addWidget(), or its separator. Returns nullptr for an action that is not in the tool bar.