QToolBar

PyQt6.QtWidgets.QToolBar

Inherits from QWidget.

Description

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

A toolbar is typically created by calling QMainWindow::addToolBar(const QString &title), but it can also be added as the first widget in a QVBoxLayout, for example.

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 createWidget() instead.

See also

QToolButton, QMenu, QAction.

Methods

__init__(parent: QWidget = None)

Constructs a QToolBar with the given parent.


__init__(str|None, parent: QWidget = None)

Constructs a QToolBar with the given parent.

The given window title identifies the toolbar and is shown in the context menu provided by QMainWindow.

See also

setWindowTitle().


actionAt(QPoint) QAction

Returns the action at point p. This function returns zero if no action was found.

See also

childAt().


actionAt(int, int) QAction

Returns the action at the point x, y. This function returns zero if no action was found.


actionEvent(QActionEvent)

TODO


actionGeometry(QAction) QRect

Returns the geometry of the toolbar item associated with the given action, or an invalid QRect if no matching item is found.


addSeparator() QAction

Adds a separator to the end of the toolbar.

See also

insertSeparator().


addWidget(QWidget) QAction

Adds the given widget to the toolbar as the toolbar’s last item.

The toolbar takes ownership of widget.

If you add a QToolButton with this method, the toolbar’s ToolButtonStyle will not be respected.

Note: You should use setVisible() to change the visibility of the widget. Using setVisible(), show() and hide() does not work.

See also

insertWidget().


allowedAreas() ToolBarArea

See also

setAllowedAreas().


changeEvent(QEvent)

TODO


clear()

Removes all actions from the toolbar.

See also

removeAction().


event(QEvent) bool

TODO


iconSize() QSize

See also

setIconSize().


initStyleOption(QStyleOptionToolBar)

TODO


insertSeparator(QAction) QAction

Inserts a separator into the toolbar in front of the toolbar item associated with the before action.

See also

addSeparator().


insertWidget(QAction, QWidget) QAction

Inserts the given widget in front of the toolbar item associated with the before action.

Note: You should use setVisible() to change the visibility of the widget. Using setVisible(), show() and hide() does not work.

See also

addWidget().


isAreaAllowed(ToolBarArea) bool

Returns true if this toolbar is dockable in the given area; otherwise returns false.


isFloatable() bool

TODO


isFloating() bool

TODO


isMovable() bool

TODO


orientation() Orientation

See also

setOrientation().


paintEvent(QPaintEvent)

TODO


setAllowedAreas(ToolBarArea)

See also

allowedAreas().


setFloatable(bool)

See also

isFloatable().


setIconSize(QSize)

See also

iconSize().


setMovable(bool)

See also

isMovable().


setOrientation(Orientation)

See also

orientation().


setToolButtonStyle(ToolButtonStyle)

See also

toolButtonStyle().


toggleViewAction() QAction

Returns a checkable action that can be used to show or hide this toolbar.

The action’s text is set to the toolbar’s window title.

See also

text(), windowTitle().


toolButtonStyle() ToolButtonStyle

widgetForAction(QAction) QWidget

Returns the widget associated with the specified action.

See also

addWidget().

Signals

actionTriggered(QAction)

This signal is emitted when an action in this toolbar is triggered. This happens when the action’s tool button is pressed, or when the action is triggered in some other way outside the toolbar. The parameter holds the triggered action.


allowedAreasChanged(ToolBarArea)

This signal is emitted when the collection of allowed areas for the toolbar is changed. The new areas in which the toolbar can be positioned are specified by allowedAreas.

See also

allowedAreas().


iconSizeChanged(QSize)

This signal is emitted when the icon size is changed. The iconSize parameter holds the toolbar’s new icon size.

See also

iconSize(), iconSize().


movableChanged(bool)

This signal is emitted when the toolbar becomes movable or fixed. If the toolbar can be moved, movable is true; otherwise it is false.

See also

movable.


orientationChanged(Orientation)

This signal is emitted when the orientation of the toolbar changes. The orientation parameter holds the toolbar’s new orientation.

See also

orientation().


toolButtonStyleChanged(ToolButtonStyle)

This signal is emitted when the tool button style is changed. The toolButtonStyle parameter holds the toolbar’s new tool button style.


topLevelChanged(bool)

This signal is emitted when the floating property changes. The topLevel parameter is true if the toolbar is now floating; otherwise it is false.

See also

isWindow().


visibilityChanged(bool)

This signal is emitted when the toolbar becomes visible (or invisible). This happens when the widget is hidden or shown.