Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The TQButton class is the abstract base class of button widgets, providing functionality common to buttons. More...
#include <qbutton.h>
Inherits TQWidget.
Inherited by TQCheckBox, TQPushButton, TQRadioButton, and TQToolButton.
If you want to create a button use TQPushButton.
The TQButton class implements an abstract button, and lets subclasses specify how to reply to user actions and how to draw the button.
TQButton provides both push and toggle buttons. The TQRadioButton and TQCheckBox classes provide only toggle buttons; TQPushButton 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.
TQButton provides most of the states used for buttons:
The difference between isDown() and isOn() is as follows: When the user clicks a toggle button to toggle it on, the button is first pressed and then released into the on state. When the user clicks it again (to toggle it off), the button moves first to the pressed state, then to the off state (isOn() and isDown() are both FALSE).
Default buttons (as used in many dialogs) are provided by TQPushButton::setDefault() and TQPushButton::setAutoDefault().
TQButton provides five signals:
If the button is a text button with an ampersand (&) in its text, TQButton creates an automatic accelerator key. This code creates a push button labelled "Rock & Roll" (where the c is underlined). The button gets an automatic accelerator key, Alt+C:
TQPushButton *p = new TQPushButton( "Ro&ck && Roll", this );
In this example, when the user presses Alt+C the button will call animateClick().
You can also set a custom accelerator using the setAccel() function. This is useful mostly for pixmap buttons because they have no automatic accelerator.
p->setPixmap( TQPixmap("print.png") ); p->setAccel( ALT+Key_F7 );
All of the buttons provided by TQt (TQPushButton, TQToolButton, TQCheckBox and TQRadioButton) can display both text and pixmaps.
To subclass TQButton, 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).
To reduce flickering, TQButton::paintEvent() sets up a pixmap that the drawButton() function draws in. You should not reimplement paintEvent() for a subclass of TQButton unless you want to take over all drawing.
See also TQButtonGroup and Abstract Widget Classes.
This enum defines the state of a toggle button.
This enum type defines what a button can do in response to a mouse/keyboard press:
If parent is a TQButtonGroup, this constructor calls TQButtonGroup::insert().
Returns the accelerator associated with the button. See the "accel" property for details.
The pressed(), released(), clicked(), toggled(), and stateChanged() signals are emitted as appropriate.
This function does nothing if the button is disabled.
See also accel.
Returns TRUE if autoRepeat is enabled; otherwise returns FALSE. See the "autoRepeat" property for details.
Returns TRUE if autoResize is enabled; otherwise returns FALSE. See the "autoResize" property for details.
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 not emitted if you call setDown().
The TQButtonGroup::clicked() signal does the same job, if you want to connect several buttons to the same slot.
Warning: Don't launch a model dialog in response to this signal for a button that has autoRepeat turned on.
See also pressed(), released(), toggled(), autoRepeat, and down.
Examples: chart/setdataform.cpp, listbox/listbox.cpp, network/clientserver/client/client.cpp, progressbar/progressbar.cpp, richtext/richtext.cpp, t2/main.cpp, and t4/main.cpp.
This virtual function is reimplemented by subclasses to draw real buttons. At some point, these reimplementations should call drawButtonLabel().
See also drawButtonLabel() and paintEvent().
This virtual function is reimplemented by subclasses to draw real buttons. It is invoked by drawButton().
See also drawButton() and paintEvent().
If the button is not a member of any TQButtonGroup, this function returns 0.
See also TQButtonGroup.
By default, the clickable area is the entire widget. Subclasses may reimplement it, though.
Returns TRUE if the button is pressed; otherwise returns FALSE. See the "down" property for details.
Returns TRUE if the button is an exclusive toggle; otherwise returns FALSE. See the "exclusiveToggle" property for details.
Returns TRUE if the button is toggled; otherwise returns FALSE. See the "on" property for details.
Returns TRUE if the button is a toggle button; otherwise returns FALSE. See the "toggleButton" property for details.
See also drawButton() and drawButtonLabel().
Reimplemented from TQWidget.
Returns the pixmap shown on the button. See the "pixmap" property for details.
This signal is emitted when the button is pressed down.
See also released() and clicked().
Examples: network/httpd/httpd.cpp and popup/popup.cpp.
This signal is emitted when the button is released.
See also pressed(), clicked(), and toggled().
Sets the accelerator associated with the button. See the "accel" property for details.
Sets whether autoRepeat is enabled. See the "autoRepeat" property for details.
Sets whether autoResize is enabled. See the "autoResize" property for details.
Sets whether the button is pressed. See the "down" property for details.
Sets the state of this button to On if on is TRUE; otherwise to Off.
See also toggleState.
Sets the pixmap shown on the button. See the "pixmap" property for details.
Sets the text shown on the button. See the "text" property for details.
If b is TRUE, this button becomes a toggle button; if b is FALSE, this button becomes a command button.
See also toggleButton.
type can be set to SingleShot, Toggle and Tristate.
Returns the state of the toggle button. See the "toggleState" property for details.
This signal is emitted whenever a toggle button changes state. state is On if the button is on, NoChange if it is in the "no change" state or Off if the button is off.
This may be the result of a user action, toggle() slot activation, setState(), or because setOn() was called.
See also clicked() and TQButton::ToggleState.
Returns the text shown on the button. See the "text" property for details.
See also on, setOn(), toggled(), and toggleButton.
Returns the type of toggle on the button. See the "toggleType" property for details.
This signal is emitted whenever a toggle button changes status. on is TRUE if the button is on, or FALSE if the button is off.
This may be the result of a user action, toggle() slot activation, or because setOn() was called.
See also clicked().
Example: listbox/listbox.cpp.
This property holds the accelerator associated with the button.
This property is 0 if there is no accelerator set. If you set this property to 0 then any current accelerator is removed.
Set this property's value with setAccel() and get this property's value with accel().
This property holds whether autoRepeat is enabled.
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.
Set this property's value with setAutoRepeat() and get this property's value with autoRepeat().
This property holds whether autoResize is enabled.
This property is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
If autoResize is enabled then the button will resize itself whenever the contents are changed.
Set this property's value with setAutoResize() and get this property's value with autoResize().
This property holds whether the button is pressed.
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.
Set this property's value with setDown() and get this property's value with isDown().
This property holds whether the button is an exclusive toggle.
If this property is TRUE and the button is in a TQButtonGroup, the button can only be toggled off by another one being toggled on. The default is FALSE.
Get this property's value with isExclusiveToggle().
This property holds whether the button is toggled.
This property should only be set for toggle buttons.
Get this property's value with isOn().
This property holds the pixmap shown on the button.
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.
pixmap() returns 0 if no pixmap was set.
Set this property's value with setPixmap() and get this property's value with pixmap().
This property holds the text shown on the button.
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.
There is no default text.
Set this property's value with setText() and get this property's value with text().
This property holds whether the button is a toggle button.
The default value is FALSE.
Get this property's value with isToggleButton().
This property holds the state of the toggle button.
If this property is changed then it does not cause the button to be repainted.
Get this property's value with state().
This property holds the type of toggle on the button.
The default toggle type is SingleShot.
See also TQButton::ToggleType.
Get this property's value with toggleType().
This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | TQt 3.3.8
|