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.

Public Types

Writable Properties

Read-Only Properties

Public Functions

Public Slots

Signals

Static Public Members

Protected Functions


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

Toolbar with Toolbuttons \caption A floating

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::BesideIconThe text appears beside the icon.
QToolButton::BelowIconThe 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:

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:

See also setMenu().

textPosition : TextPosition

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

Access functions:

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:

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:


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.


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp2