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
Methods¶
- __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
- 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
- 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
- allowedAreas() ToolBarArea
See also
- changeEvent(QEvent)
TODO
- clear()
Removes all actions from the toolbar.
See also
removeAction().
- event(QEvent) bool
TODO
- iconSize() QSize
See also
- 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
- 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
- isAreaAllowed(ToolBarArea) bool
Returns
trueif this toolbar is dockable in the given area; otherwise returnsfalse.
- isFloatable() bool
TODO
- isFloating() bool
TODO
- isMovable() bool
TODO
- orientation() Orientation
See also
- paintEvent(QPaintEvent)
TODO
- setAllowedAreas(ToolBarArea)
See also
- setFloatable(bool)
See also
- setIconSize(QSize)
See also
- setMovable(bool)
See also
- setOrientation(Orientation)
See also
- setToolButtonStyle(ToolButtonStyle)
See also
- 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
- toolButtonStyle() ToolButtonStyle
See also
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
- iconSizeChanged(QSize)
This signal is emitted when the icon size is changed. The iconSize parameter holds the toolbar’s new icon size.
See also
- 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
- toolButtonStyleChanged(ToolButtonStyle)
This signal is emitted when the tool button style is changed. The toolButtonStyle parameter holds the toolbar’s new tool button style.
See also
- 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.