Eneboo - Documentación para desarrolladores
|
The QButton class is the abstract base class of button widgets, providing functionality common to buttons. Más...
#include <qbutton.h>
The QButton class is the abstract base class of button widgets, providing functionality common to buttons.
If you want to create a button use QPushButton.
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 the "disabled" appearance when the button is disabled.
QButton provides most of the states used for buttons: isDown() indicates whether the button is pressed down. isOn() indicates whether the button is on. Only toggle buttons can be switched on and off (see below). isEnabled() indicates whether the button can be pressed by the user. setAutoRepeat() sets whether the button will auto-repeat if the user holds it down. setToggleButton() sets whether the button is a toggle button or not.
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 QPushButton::setDefault() and QPushButton::setAutoDefault().
QButton provides five signals: 1 pressed() is emitted when the button is pressed. E.g. with the mouse or when animateClick() is called. released() is emitted when the button is released. E.g. when the mouse is released or the cursor is moved outside the widget. clicked() is emitted when the button is first pressed and then released when the accelerator key is typed, or when animateClick() is called. toggled(bool) is emitted when the state of a toggle button changes. stateChanged(int) is emitted when the state of a tristate toggle button changes.
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:
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 because they have no automatic accelerator.
All of the buttons provided by Qt ( QPushButton, QToolButton, QCheckBox and QRadioButton) can display both text and pixmaps.
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).
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.
enum QButton::ToggleState |
enum QButton::ToggleState |
enum QButton::ToggleType |
enum QButton::ToggleType |
This enum type defines what a button can do in response to a mouse/keyboard press:
SingleShot pressing the button causes an action, then the button returns to the unpressed state.
Toggle pressing the button toggles it between an On
and an Off
state.
Tristate pressing the button cycles between the three states On
, Off
and NoChange
Constructs a standard button called name with parent parent, using the widget flags f.
If parent is a QButtonGroup, this constructor calls QButtonGroup::insert().
QButton::~QButton | ( | ) |
Destroys the button.
QButton::~QButton | ( | ) |
QKeySequence QButton::accel | ( | ) | const |
QKeySequence QButton::accel | ( | ) | const |
void QButton::animateClick | ( | ) | [slot] |
Performs an animated click: the button is pressed and released a short while later.
The pressed(), released(), clicked(), toggled(), and stateChanged() signals are emitted as appropriate.
This function does nothing if the button is disabled.
void QButton::animateClick | ( | ) | [slot] |
bool QButton::autoRepeat | ( | ) | const |
bool QButton::autoRepeat | ( | ) | const |
bool QButton::autoResize | ( | ) | const |
bool QButton::autoResize | ( | ) | const |
void QButton::clicked | ( | ) | [signal] |
void QButton::clicked | ( | ) | [signal] |
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 QButtonGroup::clicked() signal does the same job, if you want to connect several buttons to the same slot.
autoRepeat
turned on.virtual void QButton::drawButton | ( | QPainter * | ) | [protected, virtual] |
Reimplementado en FLCheckBox, ArrowButton, QCheckBox, QPushButton, QRadioButton, QToolButton, QCheckBox, QPushButton, QRadioButton, QToolBoxButton, QToolButton, StyledButton y ArrowButton.
void QButton::drawButton | ( | QPainter * | ) | [protected, virtual] |
Draws the button. The default implementation does nothing.
This virtual function is reimplemented by subclasses to draw real buttons. At some point, these reimplementations should call drawButtonLabel().
Reimplementado en FLCheckBox, ArrowButton, QCheckBox, QPushButton, QRadioButton, QToolButton, QCheckBox, QPushButton, QRadioButton, QToolBoxButton, QToolButton, StyledButton y ArrowButton.
void QButton::drawButtonLabel | ( | QPainter * | ) | [protected, virtual] |
Draws the button text or pixmap.
This virtual function is reimplemented by subclasses to draw real buttons. It is invoked by drawButton().
Reimplementado en QCheckBox, QPushButton, QRadioButton, QToolButton, QCheckBox, QPushButton, QRadioButton, QToolButton, StyledButton y QwtArrowButton.
virtual void QButton::drawButtonLabel | ( | QPainter * | ) | [protected, virtual] |
Reimplementado en QCheckBox, QPushButton, QRadioButton, QToolButton, QCheckBox, QPushButton, QRadioButton, QToolButton, StyledButton y QwtArrowButton.
void QButton::enabledChange | ( | bool | oldEnabled | ) | [protected, virtual] |
This virtual function is called from setEnabled(). oldEnabled is the previous setting; you can get the new setting from isEnabled().
Reimplement this function if your widget needs to know when it becomes enabled or disabled. You will almost certainly need to update the widget using update().
The default implementation repaints the visible part of the widget.
Reimplementado de QWidget.
void QButton::focusInEvent | ( | QFocusEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
Reimplementado en QPushButton y QPushButton.
void QButton::focusInEvent | ( | QFocusEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget.
A widget normally must setFocusPolicy() to something other than NoFocus
in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)
The default implementation updates the widget (except for toplevel widgets that do not specify a focusPolicy() ). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.
Reimplementado de QWidget.
Reimplementado en QPushButton y QPushButton.
void QButton::focusOutEvent | ( | QFocusEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.
A widget normally must setFocusPolicy() to something other than NoFocus
in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)
The default implementation updates the widget (except for toplevel widgets that do not specify a focusPolicy() ). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.
Reimplementado de QWidget.
Reimplementado en QPushButton y QPushButton.
void QButton::focusOutEvent | ( | QFocusEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
Reimplementado en QPushButton y QPushButton.
QButtonGroup * QButton::group | ( | ) | const |
Returns the group that this button belongs to.
If the button is not a member of any QButtonGroup, this function returns 0.
QButtonGroup* QButton::group | ( | ) | const |
Reimplementado en FLCheckBox, QCheckBox, QRadioButton, QCheckBox y QRadioButton.
Returns TRUE if pos is inside the clickable button rectangle; otherwise returns FALSE.
By default, the clickable area is the entire widget. Subclasses may reimplement it, though.
Reimplementado en FLCheckBox, QCheckBox, QRadioButton, QCheckBox y QRadioButton.
bool QButton::isDown | ( | ) | const [inline] |
bool QButton::isDown | ( | ) | const |
bool QButton::isExclusiveToggle | ( | ) | const |
bool QButton::isExclusiveToggle | ( | ) | const |
bool QButton::isOn | ( | ) | const [inline] |
bool QButton::isOn | ( | ) | const |
bool QButton::isToggleButton | ( | ) | const [inline] |
bool QButton::isToggleButton | ( | ) | const |
void QButton::keyPressEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
Reimplementado en QwtArrowButton.
void QButton::keyPressEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive key press events for the widget.
A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.
If you reimplement this handler, it is very important that you explicitly ignore the event if you do not understand it, so that the widget's parent can interpret it; otherwise, the event will be implicitly accepted. Although top-level widgets are able to choose whether to accept or ignore unknown events because they have no parent widgets that could otherwise handle them, it is good practice to explicitly ignore events to make widgets as reusable as possible.
The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored.
Reimplementado de QWidget.
Reimplementado en QwtArrowButton.
void QButton::keyReleaseEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive key release events for the widget.
A widget must accept focus initially and have focus in order to receive a key release event.
If you reimplement this handler, it is very important that you ignore() the release if you do not understand it, so that the widget's parent can interpret it.
The default implementation ignores the event.
Reimplementado de QWidget.
void QButton::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
Reimplementado en StyledButton.
void QButton::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.
Reimplementado de QWidget.
Reimplementado en StyledButton.
void QButton::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
Reimplementado en QToolButton, QToolButton y StyledButton.
void QButton::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive mouse press events for the widget.
If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.
The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.
Reimplementado de QWidget.
Reimplementado en QToolButton, QToolButton y StyledButton.
void QButton::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QButton::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive mouse release events for the widget.
Reimplementado de QWidget.
void QButton::paintEvent | ( | QPaintEvent * | ) | [protected, virtual] |
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().
Reimplementado de QWidget.
void QButton::paintEvent | ( | QPaintEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QCanvas do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::unite()). repaint() does not permit this optimization, so we suggest using update() when possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background. There are a couple of exceptions and QPaintEvent::erased() tells you whether the widget has been erased or not.
The background can be set using setBackgroundMode(), setPaletteBackgroundColor() or setBackgroundPixmap(). The documentation for setBackgroundMode() elaborates on the background; we recommend reading it.
Reimplementado de QWidget.
const QPixmap* QButton::pixmap | ( | ) | const |
Reimplementado en StyledButton.
const QPixmap* QButton::pixmap | ( | ) | const |
Reimplementado en StyledButton.
void QButton::pressed | ( | ) | [signal] |
This signal is emitted when the button is pressed down.
void QButton::pressed | ( | ) | [signal] |
void QButton::released | ( | ) | [signal] |
void QButton::released | ( | ) | [signal] |
virtual void QButton::setAccel | ( | const QKeySequence & | ) | [virtual] |
void QButton::setAccel | ( | const QKeySequence & | key | ) | [virtual] |
void QButton::setAutoRepeat | ( | bool | enable | ) | [virtual] |
virtual void QButton::setAutoRepeat | ( | bool | ) | [virtual] |
void QButton::setAutoResize | ( | bool | enable | ) |
void QButton::setAutoResize | ( | bool | ) |
void QButton::setDown | ( | bool | enable | ) | [virtual] |
virtual void QButton::setDown | ( | bool | ) | [virtual] |
void QButton::setOn | ( | bool | ) | [protected] |
Reimplementado en QPushButton, QToolButton, QPushButton y QToolButton.
void QButton::setOn | ( | bool | on | ) | [inline, protected] |
Sets the state of this button to On if on is TRUE; otherwise to Off.
Reimplementado en QPushButton, QToolButton, QPushButton y QToolButton.
virtual void QButton::setPixmap | ( | const QPixmap & | ) | [virtual] |
Reimplementado en StyledButton.
void QButton::setPixmap | ( | const QPixmap & | pixmap | ) | [virtual] |
Reimplementado en StyledButton.
virtual void QButton::setState | ( | ToggleState | ) | [protected, virtual] |
void QButton::setState | ( | ToggleState | s | ) | [protected, virtual] |
Sets the toggle state of the button to s. s can be Off
, NoChange
or On
.
virtual void QButton::setText | ( | const QString & | ) | [virtual] |
Reimplementado en QToolButton y QToolButton.
void QButton::setText | ( | const QString & | text | ) | [virtual] |
Reimplementado en QToolButton y QToolButton.
void QButton::setToggleButton | ( | bool | ) | [protected] |
Reimplementado en QPushButton, QToolButton, QPushButton y QToolButton.
void QButton::setToggleButton | ( | bool | b | ) | [inline, protected] |
If b is TRUE, this button becomes a toggle button; if b is FALSE, this button becomes a command button.
Reimplementado en QPushButton, QToolButton, QPushButton y QToolButton.
void QButton::setToggleType | ( | ToggleType | type | ) | [protected, virtual] |
Sets the toggle type of the button to type.
type can be set to SingleShot
, Toggle
and Tristate
.
virtual void QButton::setToggleType | ( | ToggleType | ) | [protected, virtual] |
ToggleState QButton::state | ( | ) | const |
QButton::ToggleState QButton::state | ( | ) | const [inline] |
void QButton::stateChanged | ( | int | state | ) | [signal] |
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.
void QButton::stateChanged | ( | int | ) | [signal] |
QString QButton::text | ( | ) | const |
QString QButton::text | ( | ) | const |
void QButton::toggle | ( | ) | [slot] |
Toggles the state of a toggle button.
Reimplementado en QToolButton y QToolButton.
void QButton::toggle | ( | ) | [slot] |
Reimplementado en QToolButton y QToolButton.
void QButton::toggled | ( | bool | on | ) | [signal] |
void QButton::toggled | ( | bool | ) | [signal] |
ToggleType QButton::toggleType | ( | ) | const |
ToggleType QButton::toggleType | ( | ) | const |
QButtonGroup [friend] |
QToolBar [friend] |
QKeySequence QButton::accel [read, write] |
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.
bool QButton::autoRepeat [inline, read, write] |
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.
bool QButton::autoResize [inline, read, write] |
whether autoResize is enabled
If autoResize is enabled then the button will resize itself whenever the contents are changed.
bool QButton::down [read, write] |
bool QButton::exclusiveToggle [read] |
whether the button is an exclusive toggle
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.
bool QButton::on [read] |
whether the button is toggled
This property should only be set for toggle buttons.
const QPixmap * QButton::pixmap [inline, read, write] |
the pixmap shown on the button
If the pixmap is monochrome (i.e. it is a QBitmap 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.
Reimplementado en StyledButton.
QString QButton::text [inline, read, write] |
the text shown on the button
This property will return a QString::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.
bool QButton::toggleButton [read] |
whether the button is a toggle button
The default value is FALSE.
ToggleState QButton::toggleState [read] |
the state of the toggle button
If this property is changed then it does not cause the button to be repainted.
QButton::ToggleType QButton::toggleType [inline, read] |
the type of toggle on the button
The default toggle type is SingleShot
.