QButton provides both push and toggle buttons. The QRadioButton and QCheckBox classes provide only toggle buttons; QPushButton and TQToolButton provide both toggle and push buttons.
Any button can have either a text or pixmap label. setText() sets the button to be a text button and setPixmap() sets it to be a pixmap button. The text/pixmap is manipulated as necessary to create the "disabled" appearance when the button is disabled.
.PP
QButton provides most of the states used for buttons:
.TP
isDown() indicates whether the button is \fIpressed\fR down.
.TP
isOn() indicates whether the button is \fIon\fR. Only toggle buttons can be switched on and off (see below).
.TP
isEnabled() indicates whether the button can be pressed by the user.
.TP
setAutoRepeat() sets whether the button will auto-repeat if the user holds it down.
.TP
setToggleButton() sets whether the button is a toggle button or not.
.PP
The difference between isDown() and isOn() is as follows: When the user clicks a toggle button to toggle it on, the button is first \fIpressed\fR and then released into the \fIon\fR state. When the user clicks it again (to toggle it off), the button moves first to the \fIpressed\fR state, then to the \fIoff\fR state (isOn() and isDown() are both FALSE).
.PP
Default buttons (as used in many dialogs) are provided by QPushButton::setDefault() and QPushButton::setAutoDefault().
.PP
QButton provides five signals: <ol type=1>
.TP
pressed() is emitted when the button is pressed. E.g. with the mouse or when animateClick() is called.
.TP
released() is emitted when the button is released. E.g. when the mouse is released or the cursor is moved outside the widget.
.TP
clicked() is emitted when the button is first pressed and then released when the accelerator key is typed, or when animateClick() is called.
.TP
toggled(bool) is emitted when the state of a toggle button changes.
.TP
stateChanged(int) is emitted when the state of a tristate toggle button changes.
.PP
If the button is a text button with an ampersand (&) in its text, QButton creates an automatic accelerator key. This code creates a push button labelled "Ro<u>c</u>k & Roll" (where the c is underlined). The button gets an automatic accelerator key, Alt+C:
.PP
.nf
.br
QPushButton *p = new QPushButton( "Ro&ck && Roll", this );
.br
.fi
.PP
In this example, when the user presses Alt+C the button will call animateClick().
.PP
You can also set a custom accelerator using the setAccel() function. This is useful mostly for pixmap buttons because they have no automatic accelerator.
To subclass QButton, you must reimplement at least drawButton() (to draw the button's outline) and drawButtonLabel() (to draw its text or pixmap). It is generally advisable to reimplement sizeHint() as well, and sometimes hitButton() (to determine whether a button press is within the button).
.PP
To reduce flickering, QButton::paintEvent() sets up a pixmap that the drawButton() function draws in. You should not reimplement paintEvent() for a subclass of QButton unless you want to take over all drawing.
.PP
See also QButtonGroup and Abstract Widget Classes.
.SS "Member Type Documentation"
.SH "QButton::ToggleState"
This enum defines the state of a toggle button.
.TP
\fCQButton::Off\fR - the button is in the "off" state
.TP
\fCQButton::NoChange\fR - the button is in the default/unchanged state
.TP
\fCQButton::On\fR - the button is in the "on" state
.SH "QButton::ToggleType"
This enum type defines what a button can do in response to a mouse/keyboard press:
.TP
\fCQButton::SingleShot\fR - pressing the button causes an action, then the button returns to the unpressed state.
.TP
\fCQButton::Toggle\fR - pressing the button toggles it between an On and an Off state.
.TP
\fCQButton::Tristate\fR - pressing the button cycles between the three states On, Off and NoChange
Constructs a standard button called \fIname\fR with parent \fIparent\fR, using the widget flags \fIf\fR.
.PP
If \fIparent\fR is a QButtonGroup, this constructor calls QButtonGroup::insert().
.SH "QButton::~QButton ()"
Destroys the button.
.SH "QKeySequence QButton::accel () const"
Returns the accelerator associated with the button. See the "accel" property for details.
.SH "void QButton::animateClick ()\fC [slot]\fR"
Performs an animated click: the button is pressed and released a short while later.
.PP
The pressed(), released(), clicked(), toggled(), and stateChanged() signals are emitted as appropriate.
.PP
This function does nothing if the button is disabled.
.PP
See also accel.
.SH "bool QButton::autoRepeat () const"
Returns TRUE if autoRepeat is enabled; otherwise returns FALSE. See the "autoRepeat" property for details.
.SH "void QButton::clicked ()\fC [signal]\fR"
This signal is emitted when the button is activated (i.e. first pressed down and then released when the mouse cursor is inside the button), when the accelerator key is typed or when animateClick() is called. This signal is \fInot\fR emitted if you call setDown().
.PP
The QButtonGroup::clicked() signal does the same job, if you want to connect several buttons to the same slot.
.PP
\fBWarning:\fR Don't launch a model dialog in response to this signal for a button that has autoRepeat turned on.
.PP
See also pressed(), released(), toggled(), autoRepeat, and down.
.PP
Examples:
.)l chart/setdataform.cpp, listbox/listbox.cpp, network/clientserver/client/client.cpp, progressbar/progressbar.cpp, richtext/richtext.cpp, t2/main.cpp, and t4/main.cpp.
Handles paint events for buttons. Small and typically complex buttons are painted double-buffered to reduce flicker. The actually drawing is done in the virtual functions drawButton() and drawButtonLabel().
Sets the text shown on the button. See the "text" property for details.
.SH "void QButton::setToggleButton ( bool b )\fC [protected]\fR"
If \fIb\fR is TRUE, this button becomes a toggle button; if \fIb\fR is FALSE, this button becomes a command button.
.PP
See also toggleButton.
.SH "void QButton::setToggleType ( ToggleType type )\fC [virtual protected]\fR"
Sets the toggle type of the button to \fItype\fR.
.PP
\fItype\fR can be set to SingleShot, Toggle and Tristate.
.SH "ToggleState QButton::state () const"
Returns the state of the toggle button. See the "toggleState" property for details.
.SH "void QButton::stateChanged ( int state )\fC [signal]\fR"
This signal is emitted whenever a toggle button changes state. \fIstate\fR is On if the button is on, NoChange if it is in the" no change" state or Off if the button is off.
.PP
This may be the result of a user action, toggle() slot activation, setState(), or because setOn() was called.
Returns the text shown on the button. See the "text" property for details.
.SH "void QButton::toggle ()\fC [slot]\fR"
Toggles the state of a toggle button.
.PP
See also on, setOn(), toggled(), and toggleButton.
.SH "ToggleType QButton::toggleType () const"
Returns the type of toggle on the button. See the "toggleType" property for details.
.SH "void QButton::toggled ( bool on )\fC [signal]\fR"
This signal is emitted whenever a toggle button changes status. \fIon\fR is TRUE if the button is on, or FALSE if the button is off.
.PP
This may be the result of a user action, toggle() slot activation, or because setOn() was called.
.PP
See also clicked().
.PP
Example: listbox/listbox.cpp.
.SS "Property Documentation"
.SH "QKeySequence accel"
This property holds the accelerator associated with the button.
.PP
This property is 0 if there is no accelerator set. If you set this property to 0 then any current accelerator is removed.
.PP
Set this property's value with setAccel() and get this property's value with accel().
.SH "bool autoRepeat"
This property holds whether autoRepeat is enabled.
.PP
If autoRepeat is enabled then the clicked() signal is emitted at regular intervals if the button is down. This property has no effect on toggle buttons. autoRepeat is off by default.
.PP
Set this property's value with setAutoRepeat() and get this property's value with autoRepeat().
.SH "bool down"
This property holds whether the button is pressed.
.PP
If this property is TRUE, the button is pressed down. The signals pressed() and clicked() are not emitted if you set this property to TRUE. The default is FALSE.
.PP
Set this property's value with setDown() and get this property's value with isDown().
.SH "bool exclusiveToggle"
This property holds whether the button is an exclusive toggle.
.PP
If this property is TRUE and the button is in a QButtonGroup, the button can only be toggled off by another one being toggled on. The default is FALSE.
.PP
Get this property's value with isExclusiveToggle().
.SH "bool on"
This property holds whether the button is toggled.
.PP
This property should only be set for toggle buttons.
If the pixmap is monochrome (i.e. it is a TQBitmap or its depth is 1) and it does not have a mask, this property will set the pixmap to be its own mask. The purpose of this is to draw transparent bitmaps which are important for toggle buttons, for example.
This property will return a TQString::null if the button has no text. If the text has an ampersand (&) in it, then an accelerator is automatically created for it using the character that follows the '&' as the accelerator key. Any previous accelerator will be overwritten, or cleared if no accelerator is defined by the text.