Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QToolButton Class Reference

The QToolButton class provides a quick-access button to commands or options, usually used inside a QToolBar. More...

    #include <QToolButton>

Inherits QAbstractButton.

- List of all members, including inherited members
- Obsolete members
- Compatibility members

### Public Types

- enum TextPosition { BesideIcon, BelowIcon, Right, Under }
- enum ToolButtonPopupMode { DelayedPopup, MenuButtonPopup, InstantPopup }

### Writable Properties

- arrowType : Qt::ArrowType
- autoRaise : bool
- iconSize : Qt::IconSize

- popupMode : ToolButtonPopupMode
- toolButtonStyle : Qt::ToolButtonStyle

- 8 writable properties inherited from QAbstractButton
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- backgroundMode : Qt::BackgroundMode

- 20 read-only properties inherited from QWidget

### Public Functions

- QToolButton ( QWidget * parent = 0 )
- ~QToolButton ()
- QAction * defaultAction () const
- QMenu * menu () const
- void setMenu ( QMenu * menu )
- void showMenu ()

- 1 public function inherited from QAbstractButton
- 92 public functions inherited from QWidget
- 26 public functions inherited from QObject
- 10 public functions inherited from QPaintDevice

### Public Slots

- void setDefaultAction ( QAction * action )
- void setIconSize ( Qt::IconSize size )
- void setToolButtonStyle ( Qt::ToolButtonStyle style )

- 4 public slots inherited from QAbstractButton
- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void triggered ( QAction * )

- 4 signals inherited from QAbstractButton
- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- virtual void nextCheckState ()
- virtual void paintEvent ( QPaintEvent * event )

- 3 protected functions inherited from QAbstractButton
- 42 protected functions inherited from QWidget
- 7 protected functions inherited from QObject

## Detailed Description

The QToolButton class provides a quick-access button to commands or options, usually used inside a QToolBar.

A tool button is a special button that provides quick-access to specific commands or options. As opposed to a normal command button, a tool button usually doesn't show a text label, but shows an icon instead. Its classic usage is to select tools, for example the "pen" tool in a drawing program. This would be implemented with a QToolButton as toggle button (see setToggleButton()).

QToolButton supports auto-raising. In auto-raise mode, the button draws a 3D frame only when the mouse points at it. The feature is automatically turned on when a button is used inside a QToolBar. Change it with setAutoRaise().

A tool button's icon is set as QIcon. This makes it possible to specify different pixmaps for the disabled and active state. The disabled pixmap is used when the button's functionality is not available. The active pixmap is displayed when the button is auto-raised because the mouse pointer is hovering over it.

The button's look and dimension is adjustable with setToolButtonStyle() and setIconSize(). When used inside a QToolBar in a QMainWindow, the button automatically adjusts to QMainWindow's settings (see QMainWindow::setToolButtonStyle() and QMainWindow::setIconSize()). The pixmap set on a QToolButton will be set to 22x22 if it is bigger than this size. If iconSize() is Qt::LargeIconSize, then the pixmap will be set to 32x32. Instead of a pixmap, a tool button can also display an arrow symbol, specified with arrowType.

A tool button can offer additional choices in a popup menu. The popup menu can be set using setMenu(). Use setPopupMode() to configure the different modes available for tool buttons with a menu set. The default mode is DelayedPopupMode which is sometimes used with the "Back" button in a web browser. After pressing and holding the button down for a while, a menu pops up showing a list of possible pages to jump to. The default delay is 600ms; you can adjust it with setPopupDelay().

QToolbar with QToolbuttons

See also QPushButton, QToolBar, QMainWindow, and GUI Design Handbook: Push Button.

## Member Type Documentation

### enum QToolButton::TextPosition

### enum QToolButton::ToolButtonPopupMode

Describes how a menu should be popped up for tool buttons that has a menu set or contains a list of actions.

`QToolButton::DelayedPopup`

After pressing and holding the tool button down for a certain amount of time (the timeout is style dependant, see QStyle::SH_ToolButton_PopupDelay), the menu is displayed. A typical application example is the "back" button in some web browsers's tool bars. If the user clicks it, the browser simply browses back to the previous page. If the user presses and holds the button down for a while, the tool button shows a menu containing the current history list

`QToolButton::MenuButtonPopup` | In this mode the tool button displays a special arrow to indicate that a menu is present. The menu is displayed when the arrow part of the button is pressed.
`QToolButton::InstantPopup` | The menu is displayed, without delay, when the tool button is pressed. In this mode, the button's own action

## Property Documentation

### arrowType : Qt::ArrowType

This property holds the arrow type which is displayed as an icon.

This displays an arrow as the icon for the QToolButton.

Access functions:

- Qt::ArrowType arrowType () const
- void setArrowType ( Qt::ArrowType type )

### autoRaise : bool

This property holds whether auto-raising is enabled or not.

The default is disabled (i.e. false).

Access functions:

- bool autoRaise () const
- void setAutoRaise ( bool enable )

### backgroundMode : Qt::BackgroundMode

This property holds the toolbutton's background mode.

Get this property with backgroundMode().

### iconSize : Qt::IconSize

This property holds the icon size used for this button.

QToolButton automatically connects this property to the relevant signal in the QMainWindow in which it resides. We strongly recommend that you use QMainWindow::iconSize() instead.

The default size is Qt::AutomaticIconSize.

Access functions:

- Qt::IconSize iconSize () const
- void setIconSize ( Qt::IconSize size )

### popupMode : ToolButtonPopupMode

Access functions:

- ToolButtonPopupMode popupMode () const
- void setPopupMode ( ToolButtonPopupMode mode )

### toolButtonStyle : Qt::ToolButtonStyle

This property holds whether the tool button displays an icon only, text only, or text beside/below the icon.

The default is Qt::ToolButtonIconOnly.

QToolButton automatically connects this slot to the relevant signal in the QMainWindow in which is resides.

Access functions:

- Qt::ToolButtonStyle toolButtonStyle () const
- void setToolButtonStyle ( Qt::ToolButtonStyle style )

## Member Function Documentation

### QToolButton::QToolButton ( QWidget * parent = 0 )

Constructs an empty tool button with parent parent.

### QToolButton::~QToolButton ()

Destroys the object and frees any allocated resources.

### QAction * QToolButton::defaultAction () const

Returns the default action.

See also setDefaultAction().

### QMenu * QToolButton::menu () const

Returns the associated menu, or 0 if no menu has been defined.

See also setMenu().

### void QToolButton::nextCheckState () `[virtual protected]`

### void QToolButton::paintEvent ( QPaintEvent * event ) `[virtual protected]`

Paints the button in response to the paint event.

Reimplemented from QWidget.

### void QToolButton::setDefaultAction ( QAction * action ) `[slot]`

Sets the default action to action.

If a tool button has a default action, the action defines the button's properties like text, icon, tool tip, etc.

### void QToolButton::setMenu ( QMenu * menu )

Associates the given menu with this tool button.

The menu will be shown according to the button's popupMode. .

Ownership of the menu is not transferred to the tool button.

See also menu().

### void QToolButton::showMenu ()

Shows (pops up) the associated popup menu. If there is no such menu, this function does nothing. This function does not return until the popup menu has been closed by the user.

### void QToolButton::triggered ( QAction * ) `[signal]`