Qt logo

QPushButton Class Reference


The QPushButton widget provides a push button with a text or pixmap label. More...

#include <qpushbutton.h>

Inherits QButton.

List of all member functions.

Public Members

Public Slots

Protected Members


Detailed Description

The QPushButton widget provides a push button with a text or pixmap label.

The push button (command button in Windows parlance) is perhaps the most central widget: Push it to command the computer to perform some action.

Being so central, the widget has grown to accomodate a great many variations in the past decade, and by now the "comand button" chapter of the Microsoft style guide shows about ten different states of Windows push buttons, and the text implies that there are dozens more when all the combinations of features are taken into consideration.

The most important modes or states are, sorted roughly by importance:

In Qt, the QButton class provides most of the modes and other API, and QPushButton provides GUI logic. See QButton for more information about the API.

See also: QRadioButton, QToolButton, GUI Design Handbook: Push Button and Microsoft Style Guide

Examples: xform/xform.cpp layout/layout.cpp drawdemo/drawdemo.cpp popup/popup.cpp qmag/qmag.cpp rot13/rot13.cpp scrollview/scrollview.cpp customlayout/main.cpp


Member Function Documentation

QPushButton::QPushButton(QWidget*parent, constchar*name=0)

Constructs a push button with no text.

The parent and name arguments are sent to the QWidget constructor.

QPushButton::QPushButton(constQString&text, QWidget*parent, constchar*name=0)

Constructs a push button with a text.

The parent and name arguments are sent to the QWidget constructor.

boolQPushButton::autoDefault()const

Returns TRUE if the button is an auto-default button.

See also: setAutoDefault().

voidQPushButton::drawButton(QPainter*paint) [virtualprotected]

Draws the push button, except its label.

See also: drawButtonLabel().

Reimplemented from QButton.

voidQPushButton::drawButtonLabel(QPainter*paint) [virtualprotected]

Draws the push button label.

See also: drawButton().

Reimplemented from QButton.

voidQPushButton::focusInEvent(QFocusEvent*e) [virtualprotected]

Handles focus in events for the push button.

Reimplemented from QWidget.

voidQPushButton::focusOutEvent(QFocusEvent*e) [virtualprotected]

Handles focus out events for the push button.

Reimplemented from QWidget.

boolQPushButton::isDefault()const

Returns TRUE if the button is default.

See also: setDefault().

boolQPushButton::isMenuButton()const

Returns TRUE if this button indicates to the user that pressing it will pop up a menu, and FALSE otherwise. The default is FALSE.

See also: setIsMenuButton().

voidQPushButton::move(constQPoint&p)

Reimplements QWidget::move() for internal purposes.

voidQPushButton::move(intx, inty)

Reimplements QWidget::move() for internal purposes.

Examples: drawdemo/drawdemo.cpp

voidQPushButton::resize(constQSize&s)

Reimplements QWidget::resize() for internal purposes.

voidQPushButton::resize(intw, inth)

Reimplements QWidget::resize() for internal purposes.

Examples: drawdemo/drawdemo.cpp

voidQPushButton::setAutoDefault(boolenable) [virtual]

Sets the push buttons to an auto-default button if enable is TRUE, or to a normal button if enable is FALSE.

An auto-default button becomes the default push button automatically when it receives the keyboard input focus.

See also: autoDefault() and setDefault().

voidQPushButton::setDefault(boolenable) [virtual]

Sets this button to be the current default button of a dialog if enable is TRUE, or to be a normal button if enable is FALSE.

The current default button gets clicked when the user presses the "Enter" key, independently of which widget in the dialog currently has the keyboard input focus. Only one push button can at any time be the default button.

The default button behaviour is only provided in dialogs. Buttons can always be clicked from the keyboard by pressing the spacebar whern the button has focus.

See also: isDefault(), setAutoDefault() and QDialog.

voidQPushButton::setGeometry(constQRect&r) [virtual]

Reimplements QWidget::setGeometry() for internal purposes.

Examples: popup/popup.cpp qmag/qmag.cpp

voidQPushButton::setGeometry(intx, inty, intw, inth) [virtual]

Reimplements QWidget::setGeometry() for internal purposes.

voidQPushButton::setIsMenuButton(boolenable) [virtual]

Tells this button to draw a menu indication triangle if enable is TRUE, and to not draw one if enable is FALSE (the default).

setIsMenuButton() does not cause the button to do anything other than draw the menu indication.

See also: isMenuButton().

voidQPushButton::setOn(boolenable) [virtualslot]

Switches a toggle button on if enable is TRUE or off if enable is FALSE.

See also: isOn(), toggle(), toggled() and isToggleButton().

Examples: qmag/qmag.cpp

voidQPushButton::setToggleButton(boolenable) [virtual]

Makes the push button a toggle button if enable is TRUE, or a normal push button if enable is FALSE.

Toggle buttons have an on/off state similar to check boxes. A push button is initially not a toggle button.

See also: setOn(), toggle(), isToggleButton() and toggled().

Examples: qmag/qmag.cpp

QSizeQPushButton::sizeHint()const [virtual]

Returns a size which fits the contents of the push button.

Reimplemented from QWidget.

QSizePolicyQPushButton::sizePolicy()const [virtual]

Specifies that this widget may stretch horizontally, but is fixed vertically.

Reimplemented from QWidget.

voidQPushButton::toggle() [slot]

Toggles the state of a toggle button.

See also: isOn(), setOn(), toggled() and isToggleButton().


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright 1999 Troll TechTrademarks
Qt version 2.0.2