
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons.More...
| Header: | #include <QAbstractButton> |
| Inherits: | QWidget |
| Inherited By: |
|
| QAbstractButton(QWidget * parent = 0) | |
| ~QAbstractButton() | |
| bool | autoExclusive() const |
| bool | autoRepeat() const |
| int | autoRepeatDelay() const |
| int | autoRepeatInterval() const |
| QButtonGroup * | group() const |
| QIcon | icon() const |
| QSize | iconSize() const |
| bool | isCheckable() const |
| bool | isChecked() const |
| bool | isDown() const |
| void | setAutoExclusive(bool) |
| void | setAutoRepeat(bool) |
| void | setAutoRepeatDelay(int) |
| void | setAutoRepeatInterval(int) |
| void | setCheckable(bool) |
| void | setDown(bool) |
| void | setIcon(const QIcon & icon) |
| void | setShortcut(const QKeySequence & key) |
| void | setText(const QString & text) |
| QKeySequence | shortcut() const |
| QString | text() const |
| void | animateClick(int msec = 100) |
| void | click() |
| void | setChecked(bool) |
| void | setIconSize(const QSize & size) |
| void | toggle() |
| virtual void | checkStateSet() |
| virtual bool | hitButton(const QPoint & pos) const |
| virtual void | nextCheckState() |
| virtual void | changeEvent(QEvent * e) |
| virtual bool | event(QEvent * e) |
| virtual void | focusInEvent(QFocusEvent * e) |
| virtual void | focusOutEvent(QFocusEvent * e) |
| virtual void | keyPressEvent(QKeyEvent * e) |
| virtual void | keyReleaseEvent(QKeyEvent * e) |
| virtual void | mouseMoveEvent(QMouseEvent * e) |
| virtual void | mousePressEvent(QMouseEvent * e) |
| virtual void | mouseReleaseEvent(QMouseEvent * e) |
| virtual void | paintEvent(QPaintEvent * e) = 0 |
| virtual void | timerEvent(QTimerEvent * e) |
TheQAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons.
This class implements anabstract button. Subclasses of this class handle user actions, and specify how the button is drawn.
QAbstractButton provides support for both push buttons and checkable (toggle) buttons. Checkable buttons are implemented in theQRadioButton andQCheckBox classes. Push buttons are implemented in theQPushButton andQToolButton classes; these also provide toggle behavior if required.
Any button can display a label containing text and an icon.setText() sets the text;setIcon() sets the icon. If a button is disabled, its label is changed to give the button a "disabled" appearance.
If the button is a text button with a string containing an ampersand ('&'),QAbstractButton automatically creates a shortcut key. For example:
QPushButton*button=newQPushButton(tr("Ro&ck && Roll"),this);
TheAlt+C shortcut is assigned to the button, i.e., when the user pressesAlt+C the button will callanimateClick(). See theQShortcut documentation for details (to display an actual ampersand, use '&&').
You can also set a custom shortcut key using thesetShortcut() function. This is useful mostly for buttons that do not have any text, because they have no automatic shortcut.
button->setIcon(QIcon(":/images/print.png"));button->setShortcut(tr("Alt+F7"));
All of the buttons provided by Qt (QPushButton,QToolButton,QCheckBox, andQRadioButton) can display bothtext andicons.
A button can be made the default button in a dialog are provided byQPushButton::setDefault() andQPushButton::setAutoDefault().
QAbstractButton provides most of the states used for buttons:
Note:As opposed to other widgets, buttons derived fromQAbstractButton accepts mouse and context menu events when disabled.
The difference betweenisDown() andisChecked() is as follows. When the user clicks a toggle button to check it, the button is firstpressed then released into thechecked state. When the user clicks it again (to uncheck it), the button moves first to thepressed state, then to theunchecked state (isChecked() andisDown() are both false).
QAbstractButton provides four signals:
To subclassQAbstractButton, you must reimplement at leastpaintEvent() to draw the button's outline and its text or pixmap. It is generally advisable to reimplementsizeHint() as well, and sometimeshitButton() (to determine whether a button press is within the button). For buttons with more than two states (like tri-state buttons), you will also have to reimplementcheckStateSet() andnextCheckState().
See alsoQButtonGroup.
This property holds whether auto-exclusivity is enabled.
If auto-exclusivity is enabled, checkable buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. In an exclusive button group, only one button can be checked at any time; checking another button automatically unchecks the previously checked one.
The property has no effect on buttons that belong to a button group.
autoExclusive is off by default, except for radio buttons.
Access functions:
| bool | autoExclusive() const |
| void | setAutoExclusive(bool) |
See alsoQRadioButton.
This property holds whether autoRepeat is enabled.
If autoRepeat is enabled, then thepressed(),released(), andclicked() signals are emitted at regular intervals when the button is down. autoRepeat is off by default. The initial delay and the repetition interval are defined in milliseconds byautoRepeatDelay andautoRepeatInterval.
Note: If a button is pressed down by a shortcut key, then auto-repeat is enabled and timed by the system and not by this class. Thepressed(),released(), andclicked() signals will be emitted like in the normal case.
Access functions:
| bool | autoRepeat() const |
| void | setAutoRepeat(bool) |
This property holds the initial delay of auto-repetition.
IfautoRepeat is enabled, then autoRepeatDelay defines the initial delay in milliseconds before auto-repetition kicks in.
This property was introduced in Qt 4.2.
Access functions:
| int | autoRepeatDelay() const |
| void | setAutoRepeatDelay(int) |
See alsoautoRepeat andautoRepeatInterval.
This property holds the interval of auto-repetition.
IfautoRepeat is enabled, then autoRepeatInterval defines the length of the auto-repetition interval in millisecons.
This property was introduced in Qt 4.2.
Access functions:
| int | autoRepeatInterval() const |
| void | setAutoRepeatInterval(int) |
See alsoautoRepeat andautoRepeatDelay.
This property holds whether the button is checkable.
By default, the button is not checkable.
Access functions:
| bool | isCheckable() const |
| void | setCheckable(bool) |
See alsochecked.
This property holds whether the button is checked.
Only checkable buttons can be checked. By default, the button is unchecked.
Access functions:
| bool | isChecked() const |
| void | setChecked(bool) |
Notifier signal:
| void | toggled(bool checked) |
See alsocheckable.
This property holds whether the button is pressed down.
If this property is true, the button is pressed down. The signalspressed() andclicked() are not emitted if you set this property to true. The default is false.
Access functions:
| bool | isDown() const |
| void | setDown(bool) |
This property holds the icon shown on the button.
The icon's default size is defined by the GUI style, but can be adjusted by setting theiconSize property.
Access functions:
| QIcon | icon() const |
| void | setIcon(const QIcon & icon) |
This property holds the icon size used for this button.
The default size is defined by the GUI style. This is a maximum size for the icons. Smaller icons will not be scaled up.
Access functions:
| QSize | iconSize() const |
| void | setIconSize(const QSize & size) |
This property holds the mnemonic associated with the button.
Access functions:
| QKeySequence | shortcut() const |
| void | setShortcut(const QKeySequence & key) |
This property holds the text shown on the button.
If the button has no text, the text() function will return a an empty string.
If the text contains an ampersand character ('&'), a shortcut is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous shortcut will be overwritten, or cleared if no shortcut is defined by the text. See theQShortcut documentation for details (to display an actual ampersand, use '&&').
There is no default text.
Access functions:
| QString | text() const |
| void | setText(const QString & text) |
Constructs an abstract button with aparent.
Destroys the button.
[slot]void QAbstractButton::animateClick(int msec = 100)Performs an animated click: the button is pressed immediately, and releasedmsec milliseconds later (the default is 100 ms).
Calling this function again before the button was released will reset the release timer.
All signals associated with a click are emitted as appropriate.
This function does nothing if the button isdisabled.
See alsoclick().
[virtual protected]void QAbstractButton::changeEvent(QEvent * e)Reimplemented fromQWidget::changeEvent().
[virtual protected]void QAbstractButton::checkStateSet()This virtual handler is called whensetChecked() was called, unless it was called from withinnextCheckState(). It allows subclasses to reset their intermediate button states.
See alsonextCheckState().
[slot]void QAbstractButton::click()Performs a click.
All the usual signals associated with a click are emitted as appropriate. If the button is checkable, the state of the button is toggled.
This function does nothing if the button isdisabled.
See alsoanimateClick().
[signal]void QAbstractButton::clicked(bool checked = false)This signal is emitted when the button is activated (i.e. pressed down then released while the mouse cursor is inside the button), when the shortcut key is typed, or whenclick() oranimateClick() is called. Notably, this signal isnot emitted if you callsetDown(),setChecked() ortoggle().
If the button is checkable,checked is true if the button is checked, or false if the button is unchecked.
See alsopressed(),released(), andtoggled().
[virtual protected]bool QAbstractButton::event(QEvent * e)Reimplemented fromQObject::event().
[virtual protected]void QAbstractButton::focusInEvent(QFocusEvent * e)Reimplemented fromQWidget::focusInEvent().
[virtual protected]void QAbstractButton::focusOutEvent(QFocusEvent * e)Reimplemented fromQWidget::focusOutEvent().
Returns the group that this button belongs to.
If the button is not a member of anyQButtonGroup, this function returns 0.
See alsoQButtonGroup.
[virtual protected]bool QAbstractButton::hitButton(constQPoint & pos) constReturns true ifpos is inside the clickable button rectangle; otherwise returns false.
By default, the clickable area is the entire widget. Subclasses may reimplement this function to provide support for clickable areas of different shapes and sizes.
[virtual protected]void QAbstractButton::keyPressEvent(QKeyEvent * e)Reimplemented fromQWidget::keyPressEvent().
[virtual protected]void QAbstractButton::keyReleaseEvent(QKeyEvent * e)Reimplemented fromQWidget::keyReleaseEvent().
[virtual protected]void QAbstractButton::mouseMoveEvent(QMouseEvent * e)Reimplemented fromQWidget::mouseMoveEvent().
[virtual protected]void QAbstractButton::mousePressEvent(QMouseEvent * e)Reimplemented fromQWidget::mousePressEvent().
[virtual protected]void QAbstractButton::mouseReleaseEvent(QMouseEvent * e)Reimplemented fromQWidget::mouseReleaseEvent().
[virtual protected]void QAbstractButton::nextCheckState()This virtual handler is called when a button is clicked. The default implementation callssetChecked(!isChecked()) if the buttonisCheckable(). It allows subclasses to implement intermediate button states.
See alsocheckStateSet().
[pure virtual protected]void QAbstractButton::paintEvent(QPaintEvent * e)Reimplemented fromQWidget::paintEvent().
[signal]void QAbstractButton::pressed()This signal is emitted when the button is pressed down.
See alsoreleased() andclicked().
[signal]void QAbstractButton::released()This signal is emitted when the button is released.
See alsopressed(),clicked(), andtoggled().
[virtual protected]void QAbstractButton::timerEvent(QTimerEvent * e)Reimplemented fromQObject::timerEvent().
[slot]void QAbstractButton::toggle()Toggles the state of a checkable button.
See alsochecked.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.