QToolBar Class
The QToolBar class provides a bar of buttons for actions. More…
| Header | #include <QToolBar> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
List of all members, including inherited members
Public Functions
| QToolBar(const QString &title, QWidget *parent = nullptr) | |
| QToolBar(QWidget *parent = nullptr) | |
| ~QToolBar() | |
| void | setMovable(bool movable) |
| bool | isMovable() const |
| void | setAllowedAreas(Qt::ToolBarAreas areas) |
| Qt::ToolBarAreas | allowedAreas() const |
| bool | isAreaAllowed(Qt::ToolBarArea area) const |
| void | setOrientation(Qt::Orientation orientation) |
| Qt::Orientation | orientation() const |
| void | clear() |
| 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) |
| QRect | actionGeometry(QAction *action) const |
| QAction * | actionAt(const QPoint &p) const |
| QAction * | actionAt(int x, int y) const |
| QAction * | toggleViewAction() const |
| Qt::ToolButtonStyle | toolButtonStyle() const |
| QWidget * | widgetForAction(QAction *action) const |
| bool | isFloatable() const |
| void | setFloatable(bool floatable) |
| bool | isFloating() const |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Public Slots
| void | setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle) |
Signals
| void | actionTriggered(QAction *action) |
| void | movableChanged(bool movable) |
| void | allowedAreasChanged(Qt::ToolBarAreas allowedAreas) |
| void | orientationChanged(Qt::Orientation orientation) |
| void | toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle) |
| void | topLevelChanged(bool topLevel) |
| void | visibilityChanged(bool visible) |
Reimplemented Protected Functions
| void | actionEvent(QActionEvent *event) |
| void | paintEvent(QPaintEvent *event) |
| void | showEvent(QShowEvent *event) |
| void | hideEvent(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
QToolBar::QToolBar(const QString &title, QWidget *parent = nullptr)
Constructs a tool bar with the given window title, which names it in toggleViewAction(), and parent.
QToolBar::QToolBar(QWidget *parent = nullptr)
Constructs a tool bar with the given parent.
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.
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.
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().
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.
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().
QSize QToolBar::minimumSizeHint() const
Reimplements QWidget::minimumSizeHint().
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().
void QToolBar::orientationChanged(Qt::Orientation orientation)
This signal is emitted when the orientation changes to orientation.
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().
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().
void QToolBar::showEvent(QShowEvent *event)
Reimplements QWidget::showEvent().
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().
void QToolBar::toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
This signal is emitted when the style of the buttons changes to toolButtonStyle.
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.
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.