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 }

### Writable Properties

autoRaise : bool popupDelay : int textPosition : TextPosition | usesBigPixmap : bool usesTextLabel : bool

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

### Read-Only Properties

- backgroundMode : Qt::BackgroundMode

- 24 read-only properties inherited from QWidget

### Public Functions

- QToolButton ( QWidget * parent = 0 )
- QToolButton ( Qt::ArrowType type, QWidget * parent = 0 )
- ~QToolButton ()
- QMenu * menu () const
- void setMenu ( QMenu * menu )
- void showMenu ()

- 1 public function inherited from QAbstractButton
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- void setTextPosition ( TextPosition pos )
- void setUsesBigPixmap ( bool enable )
- void setUsesTextLabel ( bool enable )

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

### Signals

- 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

- void drawBevel ( QPainter * p )
- void drawLabel ( QPainter * p )
- virtual void paintEvent ( QPaintEvent * event )

- 3 protected functions inherited from QAbstractButton
- 44 protected functions inherited from QWidget
- 9 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 setUsesBigPixmap() and setUsesTextLabel(). When used inside a QToolBar in a QMainWindow, the button automatically adjusts to QMainWindow's settings (see QMainWindow::setUsesTextLabel() and QMainWindow::setUsesBigPixmaps()). The pixmap set on a QToolButton will be set to 22x22 if it is bigger than this size. If usesBigPixmap() is true, then the pixmap will be set to 32x32.

A tool button can offer additional choices in a popup menu. The feature 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. With QToolButton you can set a popup menu using setMenu(). 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

The position of the tool button's textLabel in relation to the tool button's icon.

`QToolButton::BesideIcon` | The text appears beside the icon.
`QToolButton::BelowIcon` | The text appears below the icon.

## Property Documentation

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

### popupDelay : int

This property holds the time delay between pressing the button and the moment the associated menu pops up in milliseconds.

Usually this is around half a second. A value of 0 will add a special section to the tool button that can be used to open the menu.

Access functions:

- int popupDelay () const
- void setPopupDelay ( int delay )

See also setMenu().

### textPosition : TextPosition

This property holds the position of the text label of this button.

Access functions:

- TextPosition textPosition () const
- void setTextPosition ( TextPosition pos )

### usesBigPixmap : bool

This property holds whether this toolbutton uses big pixmaps.

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

This property's default is true.

Warning: If you set some buttons (in a QMainWindow) to have big pixmaps and others to have small pixmaps, QMainWindow may not get the geometry right.

Access functions:

- bool usesBigPixmap () const
- void setUsesBigPixmap ( bool enable )

### usesTextLabel : bool

This property holds whether the toolbutton displays a text label below the button pixmap.

The default is false.

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

Access functions:

- bool usesTextLabel () const
- void setUsesTextLabel ( bool enable )

## Member Function Documentation

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

Constructs an empty tool button with parent parent.

### QToolButton::QToolButton ( Qt::ArrowType type, QWidget * parent = 0 )

Constructs a tool button as an arrow button. The `Qt::ArrowType` type defines the arrow direction. Possible values are `Qt::LeftArrow`, `Qt::RightArrow`, `Qt::UpArrow` and `Qt::DownArrow`.

An arrow button has auto-repeat turned on by default.

The parent argument is passed to the QWidget constructor.

### QToolButton::~QToolButton ()

Destroys the object and frees any allocated resources.

### void QToolButton::drawBevel ( QPainter * p ) `[protected]`

Draws the tool button bevel on painter p. Called from paintEvent().

See also drawLabel().

### void QToolButton::drawLabel ( QPainter * p ) `[protected]`

Draws the tool button label on painter p. Called from paintEvent().

See also drawBevel().

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

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

See also setMenu().

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

Paints the button in response to the paint event, by first calling drawBevel() and then drawLabel(). If you reimplement paintEvent() just to draw a different label, you can call drawBevel() from your own code. For example:

        QPainter p(this);
        drawBevel(&p);
        // ... your label drawing code

Reimplemented from QWidget.

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

Associates the given menu with this tool button.

The menu will be shown each time the tool button has been pressed down for popupDelay amount of time. 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.

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.