|  | Home · All Classes · Modules

# QToolBar Class Reference
[QtGui module]

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

Inherits QWidget.

### Methods

- __init__ (self, QString title, QWidget parent = None)
- __init__ (self, QWidget parent = None)
- QAction actionAt (self, QPoint p)
- QAction actionAt (self, int ax, int ay)
- actionEvent (self, QActionEvent event)
- QRect actionGeometry (self, QAction action)
- addAction (self, QAction action)
- QAction addAction (self, QString text)
- QAction addAction (self, QIcon icon, QString text)
- QAction addAction (self, QString text, QObject receiver, SLOT()SLOT() member)
- QAction addAction (self, QString text, callable receiver)
- QAction addAction (self, QIcon icon, QString text, QObject receiver, SLOT()SLOT() member)
- QAction addAction (self, QIcon icon, QString text, callable receiver)
- QAction addSeparator (self)
- QAction addWidget (self, QWidget widget)
- Qt.ToolBarAreas allowedAreas (self)
- changeEvent (self, QEvent event)
- childEvent (self, QChildEvent event)
- clear (self)
- bool event (self, QEvent event)
- QSize iconSize (self)
- initStyleOption (self, QStyleOptionToolBar option)
- QAction insertSeparator (self, QAction before)
- QAction insertWidget (self, QAction before, QWidget widget)
- bool isAreaAllowed (self, Qt.ToolBarArea area)
- bool isFloatable (self)
- bool isFloating (self)
- bool isMovable (self)
- Qt.Orientation orientation (self)
- paintEvent (self, QPaintEvent event)
- resizeEvent (self, QResizeEvent event)
- setAllowedAreas (self, Qt.ToolBarAreas areas)
- setFloatable (self, bool floatable)
- setIconSize (self, QSize iconSize)
- setMovable (self, bool movable)
- setOrientation (self, Qt.Orientation orientation)
- setToolButtonStyle (self, Qt.ToolButtonStyle toolButtonStyle)
- QAction toggleViewAction (self)
- Qt.ToolButtonStyle toolButtonStyle (self)
- QWidget widgetForAction (self, QAction action)

### Qt Signals

- void actionTriggered (QAction *)
- void allowedAreasChanged (Qt::ToolBarAreas)
- void iconSizeChanged (const QSize&)
- void movableChanged (bool)
- void orientationChanged (Qt::Orientation)
- void toolButtonStyleChanged (Qt::ToolButtonStyle)
- void topLevelChanged (bool)
- void visibilityChanged (bool)

## Detailed Description

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

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 (isMovable()) between toolbar areas; see 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 does not currently fit in the toolbar.

When a QToolBar is not a child of a QMainWindow, it looses 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.

## Method Documentation

### QToolBar.__init__ (self, QString title, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

### QToolBar.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QToolBar with the given parent.

### QAction QToolBar.actionAt (self, QPoint p)

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

See also QWidget.childAt().

### QAction QToolBar.actionAt (self, int ax, int ay)

This is an overloaded function.

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

### QToolBar.actionEvent (self, QActionEvent event)

Reimplemented from QWidget.actionEvent().

### QRect QToolBar.actionGeometry (self, QAction action)

### QToolBar.addAction (self, QAction action)

This is an overloaded function.

Appends the action action to the toolbar's list of actions.

See also QMenu.addAction() and QWidget.addAction().

### QAction QToolBar.addAction (self, QString text)

This is an overloaded function.

Creates a new action with the given text. This action is added to the end of the toolbar.

### QAction QToolBar.addAction (self, QIcon icon, QString text)

This is an overloaded function.

Creates a new action with the given icon and text. This action is added to the end of the toolbar.

### QAction QToolBar.addAction (self, QString text, QObject receiver, SLOT()SLOT() member)

This is an overloaded function.

Creates a new action with the given text. This action is added to the end of the toolbar. The action's triggered() signal is connected to member in receiver.

### QAction QToolBar.addAction (self, QString text, callable receiver)

This is an overloaded function.

Creates a new action with the icon icon and text text. This action is added to the end of the toolbar. The action's triggered() signal is connected to member in receiver.

### QAction QToolBar.addAction (self, QIcon icon, QString text, QObject receiver, SLOT()SLOT() member)

### QAction QToolBar.addAction (self, QIcon icon, QString text, callable receiver)

### QAction QToolBar.addSeparator (self)

Adds a separator to the end of the toolbar.

See also insertSeparator().

### QAction QToolBar.addWidget (self, QWidget widget)

The widget argument has it's ownership transferred to Qt.

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 tools bar's Qt.ToolButtonStyle will not be respected.

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

See also insertWidget().

### Qt.ToolBarAreas QToolBar.allowedAreas (self)

### QToolBar.changeEvent (self, QEvent event)

Reimplemented from QWidget.changeEvent().

### QToolBar.childEvent (self, QChildEvent event)

Reimplemented from QObject.childEvent().

### QToolBar.clear (self)

Removes all actions from the toolbar.

See also removeAction().

### bool QToolBar.event (self, QEvent event)

Reimplemented from QObject.event().

### QSize QToolBar.iconSize (self)

### QToolBar.initStyleOption (self, QStyleOptionToolBar option)

### QAction QToolBar.insertSeparator (self, QAction before)

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

See also addSeparator().

### QAction QToolBar.insertWidget (self, QAction before, QWidget widget)

The widget argument has it's ownership transferred to Qt.

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

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

See also addWidget().

### bool QToolBar.isAreaAllowed (self, Qt.ToolBarArea area)

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

### bool QToolBar.isFloatable (self)

### bool QToolBar.isFloating (self)

### bool QToolBar.isMovable (self)

### Qt.Orientation QToolBar.orientation (self)

### QToolBar.paintEvent (self, QPaintEvent event)

Reimplemented from QWidget.paintEvent().

### QToolBar.resizeEvent (self, QResizeEvent event)

Reimplemented from QWidget.resizeEvent().

### QToolBar.setAllowedAreas (self, Qt.ToolBarAreas areas)

### QToolBar.setFloatable (self, bool floatable)

### QToolBar.setIconSize (self, QSize iconSize)

This method is also a Qt slot with the C++ signature `void setIconSize(const QSize&)`.

### QToolBar.setMovable (self, bool movable)

### QToolBar.setOrientation (self, Qt.Orientation orientation)

### QToolBar.setToolButtonStyle (self, Qt.ToolButtonStyle toolButtonStyle)

This method is also a Qt slot with the C++ signature `void setToolButtonStyle(Qt::ToolButtonStyle)`.

### QAction QToolBar.toggleViewAction (self)

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 QAction.text and QWidget.windowTitle.

### Qt.ToolButtonStyle QToolBar.toolButtonStyle (self)

### QWidget QToolBar.widgetForAction (self, QAction action)

Returns the widget associated with the specified action.

This function was introduced in Qt 4.2.

See also addWidget().

## Qt Signal Documentation

### void actionTriggered (QAction *)

This is the default overload of this signal.

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 tool bar. The parameter holds the triggered action.

### void allowedAreasChanged (Qt::ToolBarAreas)

This is the default overload of this signal.

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.

### void iconSizeChanged (const QSize&)

This is the default overload of this signal.

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

See also iconSize and QMainWindow.iconSize.

### void movableChanged (bool)

This is the default overload of this signal.

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.

### void orientationChanged (Qt::Orientation)

This is the default overload of this signal.

This signal is emitted when the orientation of the toolbar changes. The new orientation is specified by the orientation given.

See also orientation.

### void toolButtonStyleChanged (Qt::ToolButtonStyle)

This is the default overload of this signal.

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

See also toolButtonStyle and QMainWindow.toolButtonStyle.

### void topLevelChanged (bool)

This is the default overload of this signal.

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

This function was introduced in Qt 4.6.

See also isWindow().

### void visibilityChanged (bool)

This is the default overload of this signal.

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

This function was introduced in Qt 4.7.