Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference |
|
The QButton class is the abstract base class of button widgets, providing functionality common to buttons. More...
#include <qbutton.h>
Inherits QWidget.
Inherited by QToolButton, QPushButton, QCheckBox, and QRadioButton.
The QButton class is the abstract base class of button widgets, providing functionality common to buttons.
The QButton class implements an abstract button, and lets subclasses specify how to reply to user actions and how to draw the button.
QButton provides both push and toggle buttons. The QRadioButton and QCheckBox classes provide only toggle buttons, QPushButton and QToolButton 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 "disabled" appearance when the button is disabled.
QButton 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, then released into 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 QPushButton::setDefault() and QPushButton::setAutoDefault().
QButton provides four signals:
If the button is a text button with "&" in its text, QButton creates an automatic accelerator key. This code creates a push button labelled "Rock & Roll" (where the c is underscored). The button gets an automatic accelerator key, Alt-C:
QPushButton *p = new QPushButton( "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 since they have no automatic accelerator.
QPushButton *p;
p->setPixmap( QPixmap("print.png") );
p->setAccel( ALT+Key_F7 );
All of the buttons provided by Qt (QPushButton, QToolButton, QCheckBox and QRadioButton) can display both text and pixmaps.
To subclass QButton, you have to reimplement at least drawButton() (to draw the button's outskirts) 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 the 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.
See also QButtonGroup.
This enum defines the state of a toggle button at any moment. The possible values are:
This enum type defines what a button can do in response to a mouse/keyboard press:
If parent is a QButtonGroup, this constructor calls QButtonGroup::insert().
See also setAccel().
pressed(), released(), clicked(), toggled(), and stateChanged() signals are emitted as appropriate.
This function does nothing if the button is disabled.
See also setAccel().
Returns TRUE if the button is auto-repeating, else FALSE.
The default is FALSE.
See also setAutoRepeat().
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Strange pre-layout stuff.
Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing is disabled.
Auto-resizing is disabled by default.
See also setAutoResize().
This virtual function is reimplemented by subclasses to draw real buttons. At some point in time, these reimplementations are supposed to call drawButtonLabel().
See also drawButtonLabel() and paintEvent().
This virtual function is reimplemented by subclasses to draw real buttons. It's invoked by drawButton().
See also drawButton() and paintEvent().
If the button is not a member of any QButtonGroup, this function returns 0.
See also setGroup() and QButtonGroup.
Per default, the clickable area is the entire widget. Subclasses may reimplement it, though.
See also setDown().
See also setOn() and isToggleButton().
See also setToggleButton().
See also drawButton() and drawButtonLabel().
Reimplemented from QWidget.
See also released() and clicked().
See also pressed(), clicked(), and toggled().
Setting a button text containing a shortcut character (for example the 'x' in E&xit) automatically defines an ALT+letter accelerator for the button. You only need to call this function in order to specify a custom accelerator.
Example:
QPushButton *b1 = new QPushButton;
b1->setText( "&OK" ); // sets accel ALT+'O'
QPushButton *b2 = new QPushButton;
b2->setPixmap( printIcon ); // pixmap instead of text
b2->setAccel( CTRL+'P' ); // custom accel
See also accel(), setText(), and QAccel.
When auto-repeat is enabled, the clicked() signal is emitted at regular intervals while the buttons is down.
setAutoRepeat() has no effect for toggle buttons.
See also isDown(), autoRepeat(), and clicked().
Strange pre-layout stuff.
Enables auto-resizing if enable is TRUE, or disables it if enable is FALSE.
When auto-resizing is enabled, the button will resize itself whenever the contents change.
See also autoResize() and adjustSize().
If the button is a toggle button, it is not toggled. Call toggle() as well if you need to do that. The pressed() and released() signals are not emitted by this function.
This method is provided in case you need to reimplement the mouse event handlers.
See also isDown(), setOn(), toggle(), and toggled().
Switches a toggle button on if enable is TRUE or off if enable is FALSE. This function should be called only for toggle buttons.
See also isOn() and isToggleButton().
If pixmap is monochrome (i.e. it is a QBitmap or its depth is 1) and it does not have a mask, this function sets the pixmap to be its own mask. The purpose of this is to draw transparent bitmaps, which is important for e.g. toggle buttons.
See also pixmap(), setText(), setAccel(), and QPixmap::mask().
This protected function sets the button state into state t but does not cause repainting.
See also setToggleType().
If the text contains an ampersand, QButton creates an automatic accelerator for it, such as Alt-c for "&Cancel".
See also text(), setPixmap(), setAccel(), and QPixmap::mask().
Makes the button a toggle button if enable is TRUE, or a normal button if enable is FALSE.
Note that this function is protected. It is called from subclasses to enable the toggle functionality. QCheckBox and QRadioButton are toggle buttons. QPushButton is initially not a toggle button, but QPushButton::setToggleButton() can be called to create toggle buttons.
See also isToggleButton().
Subclasses use this, and present it with a more comfortable interface.
See also ToggleState, ToggleType, and setState().
This may be the result of a user action, toggle() slot activation, setState(), or because setOn() was called.
See also clicked().
See also setText().
Returns the current toggle type.
See also setToggleType().
This may be the result of a user action, toggle() slot activation, or because setOn() was called.
See also clicked().
This file is part of the Qtopia platform, copyright © 1995-2005 Trolltech, all rights reserved.
| Copyright © 2005 Trolltech | Trademarks | Qtopia version 2.2.0
|