#include <qabstractbutton.h>
Inheritance diagram for QAbstractButton:


This class implements an abstract 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 the QRadioButton and QCheckBox classes. Push buttons are implemented in the QPushButton and QToolButton 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 = new QPushButton(tr("Ro&ck && Roll"), this);
The Alt+C shortcut is assigned to the button, i.e., when the user presses Alt+C the button will call animateClick(). See the {QShortcut::mnemonic}{QShortcut} documentation for details (to display an actual ampersand, use '&&').
You can also set a custom shortcut key using the setShortcut() 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, and QRadioButton) can display both text and {icon}{icons}.
A button can be made the default button in a dialog are provided by QPushButton::setDefault() and QPushButton::setAutoDefault().
QAbstractButton provides most of the states used for buttons:
isDown() indicates whether the button is pressed down.
isChecked() indicates whether the button is checked. Only checkable buttons can be checked and unchecked (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. autoRepeatDelay and autoRepeatInterval define how auto-repetition is done.
setCheckable() sets whether the button is a toggle button or not.
The difference between isDown() and isChecked() is as follows. When the user clicks a toggle button to check it, the button is first pressed then released into the checked state. When the user clicks it again (to uncheck it), the button moves first to the pressed state, then to the unchecked state (isChecked() and isDown() are both false).
QAbstractButton provides four signals:
1
pressed() is emitted when the left mouse button is pressed while the mouse cursor is inside the button.
released() is emitted when the left mouse button is released.
clicked() is emitted when the button is first pressed and then released, when the shortcut key is typed, or when click() or animateClick() is called.
toggled() is emitted when the state of a toggle button changes.
To subclass QAbstractButton, you must reimplement at least paintEvent() to draw the button's outline and 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). For buttons with more than two states (like tri-state buttons), you will also have to reimplement checkStateSet() and nextCheckState().
Definition at line 38 of file qabstractbutton.h.
Public Slots | |
| void | setIconSize (const QSize &size) |
| void | animateClick (int msec=100) |
| void | click () |
| void | toggle () |
| void | setChecked (bool) |
Signals | |
| void | pressed () |
| void | released () |
| void | clicked (bool checked=false) |
| void | toggled (bool checked) |
Public Member Functions | |
| QAbstractButton (QWidget *parent=0) | |
| ~QAbstractButton () | |
| void | setText (const QString &text) |
| QString | text () const |
| void | setIcon (const QIcon &icon) |
| QIcon | icon () const |
| QSize | iconSize () const |
| void | setShortcut (const QKeySequence &key) |
| QKeySequence | shortcut () const |
| void | setCheckable (bool) |
| bool | isCheckable () const |
| bool | isChecked () const |
| void | setDown (bool) |
| bool | isDown () const |
| void | setAutoRepeat (bool) |
| bool | autoRepeat () const |
| void | setAutoRepeatDelay (int) |
| int | autoRepeatDelay () const |
| void | setAutoRepeatInterval (int) |
| int | autoRepeatInterval () const |
| void | setAutoExclusive (bool) |
| bool | autoExclusive () const |
| QButtonGroup * | group () const |
Protected Member Functions | |
| virtual void | paintEvent (QPaintEvent *e)=0 |
| virtual bool | hitButton (const QPoint &pos) const |
| virtual void | checkStateSet () |
| virtual void | nextCheckState () |
| bool | event (QEvent *e) |
| void | keyPressEvent (QKeyEvent *e) |
| void | keyReleaseEvent (QKeyEvent *e) |
| void | mousePressEvent (QMouseEvent *e) |
| void | mouseReleaseEvent (QMouseEvent *e) |
| void | mouseMoveEvent (QMouseEvent *e) |
| void | focusInEvent (QFocusEvent *e) |
| void | focusOutEvent (QFocusEvent *e) |
| void | changeEvent (QEvent *e) |
| void | timerEvent (QTimerEvent *e) |
| QAbstractButton (QAbstractButtonPrivate &dd, QWidget *parent=0) | |
Friends | |
| class | QButtonGroup |
| QAbstractButton::QAbstractButton | ( | QWidget * | parent = 0 |
) | [explicit] |
Constructs an abstract button with a parent.
Definition at line 555 of file qabstractbutton.cpp.
References d.
00556 :QWidget(*new QAbstractButtonPrivate, parent, 0) 00557 { 00558 Q_D(QAbstractButton); 00559 d->init(); 00560 }
| QAbstractButton::~QAbstractButton | ( | ) |
Destroys the button.
Definition at line 565 of file qabstractbutton.cpp.
References d.
00566 { 00567 #ifndef QT_NO_BUTTONGROUP 00568 Q_D(QAbstractButton); 00569 if (d->group) 00570 d->group->removeButton(this); 00571 #endif 00572 }
| QAbstractButton::QAbstractButton | ( | QAbstractButtonPrivate & | dd, | |
| QWidget * | parent = 0 | |||
| ) | [protected] |
Definition at line 577 of file qabstractbutton.cpp.
References d.
00578 : QWidget(dd, parent, 0) 00579 { 00580 Q_D(QAbstractButton); 00581 d->init(); 00582 }
| void QAbstractButton::setText | ( | const QString & | text | ) |
Definition at line 601 of file qabstractbutton.cpp.
References d, QKeySequence::isEmpty(), QKeySequence::mnemonic(), QAccessible::NameChanged, setShortcut(), text(), QWidget::update(), QAccessible::updateAccessibility(), and QWidget::updateGeometry().
Referenced by QMessageBoxPrivate::_q_buttonClicked(), QCalendarWidgetPrivate::_q_monthChanged(), QCalendarWidgetPrivate::_q_yearEditingFinished(), Button::Button(), MainWindow::changeStyle(), CompositionWidget::CompositionWidget(), FtpWindow::connectOrDisconnect(), FindFileDialog::createButtons(), Q3CheckTableItem::createEditor(), GradientWidget::GradientWidget(), Main::Main(), qdesigner_internal::PaletteEditorButton::PaletteEditorButton(), PathDeformWidget::PathDeformWidget(), PathStrokeWidget::PathStrokeWidget(), Q3TabDialog::Q3TabDialog(), Q3Wizard::Q3Wizard(), QCheckBox::QCheckBox(), QPushButton::QPushButton(), QRadioButton::QRadioButton(), qdesigner_internal::Sentinel::Sentinel(), Q3TabDialog::setApplyButton(), Q3TabDialog::setCancelButton(), Q3ProgressDialog::setCancelButtonText(), QToolButton::setDefaultAction(), Q3TabDialog::setDefaultButton(), Q3TabDialog::setHelpButton(), QFileDialog::setLabelText(), Q3FileDialog::setMode(), Q3TabDialog::setOkButton(), QToolBoxPrivate::Page::setText(), Q3CheckTableItem::setText(), qdesigner_internal::StringListEditorButton::StringListEditorButton(), AnimationSaveWidget::toggleRecord(), QCalendarWidgetPrivate::updateHeader(), View::View(), and XFormWidget::XFormWidget().
00602 { 00603 Q_D(QAbstractButton); 00604 if (d->text == text) 00605 return; 00606 d->text = text; 00607 #ifndef QT_NO_SHORTCUT 00608 QKeySequence newMnemonic = QKeySequence::mnemonic(text); 00609 if (!newMnemonic.isEmpty()) 00610 setShortcut(newMnemonic); 00611 #endif 00612 update(); 00613 updateGeometry(); 00614 #ifndef QT_NO_ACCESSIBILITY 00615 QAccessible::updateAccessibility(this, 0, QAccessible::NameChanged); 00616 #endif 00617 }
Here is the call graph for this function:

| QString QAbstractButton::text | ( | ) | const |
Definition at line 619 of file qabstractbutton.cpp.
References d.
Referenced by QFileDialog::accept(), Calculator::additiveOperatorClicked(), Button::Button(), Calculator::digitClicked(), qdesigner_internal::ButtonTaskMenu::editText(), getStyleOption(), QFileDialog::labelText(), Calculator::multiplicativeOperatorClicked(), QToolBoxButton::paintEvent(), QCheckBox::QCheckBox(), QPushButton::QPushButton(), QRadioButton::QRadioButton(), setText(), QCheckBox::sizeHint(), QRadioButton::sizeHint(), QPushButton::sizeHint(), QToolBoxButton::sizeHint(), QToolButton::sizeHint(), QToolBoxPrivate::Page::text(), QAccessibleButton::text(), QAccessibleToolButton::text(), and Calculator::unaryOperatorClicked().
00620 { 00621 Q_D(const QAbstractButton); 00622 return d->text; 00623 }
| void QAbstractButton::setIcon | ( | const QIcon & | icon | ) |
Definition at line 633 of file qabstractbutton.cpp.
References d, icon(), QWidget::update(), and QWidget::updateGeometry().
Referenced by QDialogButtonBoxPrivate::createButton(), MoviePlayer::createButtons(), QCalendarWidgetPrivate::createHeader(), SortingBox::createToolButton(), EditorWithReset::EditorWithReset(), FtpWindow::FtpWindow(), qdesigner_internal::GraphicsPropertyEditor::init(), TabbedBrowser::init(), ImageComposer::loadImage(), Main::Main(), PathStrokeWidget::PathStrokeWidget(), QBalloonTip::QBalloonTip(), QMenuBarExtension::QMenuBarExtension(), QPushButton::QPushButton(), qdesigner_internal::ResourceEditor::ResourceEditor(), qdesigner_internal::RoleEditor::RoleEditor(), QToolButton::setDefaultAction(), QToolBoxPrivate::Page::setIcon(), Q3ToolBarExtensionWidget::setOrientation(), QToolBarExtension::setOrientation(), QFileDialogPrivate::setupToolButtons(), QWorkspacePrivate::showMaximizeControls(), qdesigner_internal::SignalSlotEditorWindow::SignalSlotEditorWindow(), QDockWidgetPrivate::updateButtons(), Q3DockWindowHandle::updateGui(), and View::View().
00634 { 00635 Q_D(QAbstractButton); 00636 d->icon = icon; 00637 update(); 00638 updateGeometry(); 00639 }
Here is the call graph for this function:

| QIcon QAbstractButton::icon | ( | ) | const |
Definition at line 641 of file qabstractbutton.cpp.
References d.
Referenced by getStyleOption(), QToolBoxPrivate::Page::icon(), QToolBoxButton::minimumSizeHint(), QDockWidgetTitleButton::paintEvent(), QToolBoxButton::paintEvent(), QPushButton::QPushButton(), setIcon(), QDockWidgetTitleButton::sizeHint(), QPushButton::sizeHint(), QToolBoxButton::sizeHint(), and QToolButton::sizeHint().
00642 { 00643 Q_D(const QAbstractButton); 00644 return d->icon; 00645 }
| QSize QAbstractButton::iconSize | ( | ) | const |
Definition at line 1308 of file qabstractbutton.cpp.
References d, QStyle::pixelMetric(), QStyle::PM_ButtonIconSize, and QWidget::style().
Referenced by getStyleOption(), and QToolBoxButton::sizeHint().
01309 { 01310 Q_D(const QAbstractButton); 01311 if (d->iconSize.isValid()) 01312 return d->iconSize; 01313 int e = style()->pixelMetric(QStyle::PM_ButtonIconSize); 01314 return QSize(e, e); 01315 }
Here is the call graph for this function:

| void QAbstractButton::setShortcut | ( | const QKeySequence & | key | ) |
Definition at line 653 of file qabstractbutton.cpp.
References d, QWidget::grabShortcut(), key, and QWidget::releaseShortcut().
Referenced by setText().
00654 { 00655 Q_D(QAbstractButton); 00656 if (d->shortcutId != 0) 00657 releaseShortcut(d->shortcutId); 00658 d->shortcut = key; 00659 d->shortcutId = grabShortcut(key); 00660 }
Here is the call graph for this function:

| QKeySequence QAbstractButton::shortcut | ( | ) | const |
Definition at line 662 of file qabstractbutton.cpp.
References d.
Referenced by QMessageBox::keyPressEvent().
00663 { 00664 Q_D(const QAbstractButton); 00665 return d->shortcut; 00666 }
| void QAbstractButton::setCheckable | ( | bool | ) |
Definition at line 677 of file qabstractbutton.cpp.
References d.
Referenced by CompositionWidget::CompositionWidget(), MoviePlayer::createButtons(), Window::createPushButtonGroup(), WidgetGallery::createTopRightGroupBox(), GradientWidget::GradientWidget(), PathDeformWidget::PathDeformWidget(), PathStrokeWidget::PathStrokeWidget(), qRadioButtonInit(), QToolButton::setDefaultAction(), View::View(), and XFormWidget::XFormWidget().
00678 { 00679 Q_D(QAbstractButton); 00680 if (d->checkable == checkable) 00681 return; 00682 00683 d->checkable = checkable; 00684 d->checked = false; 00685 }
| bool QAbstractButton::isCheckable | ( | ) | const |
Definition at line 687 of file qabstractbutton.cpp.
References d.
Referenced by AccessibleFactory::create(), nextCheckState(), and Q3ButtonGroup::selected().
00688 { 00689 Q_D(const QAbstractButton); 00690 return d->checkable; 00691 }
| bool QAbstractButton::isChecked | ( | ) | const |
Definition at line 736 of file qabstractbutton.cpp.
References d.
Referenced by QButtonGroup::addButton(), WidgetGallery::changePalette(), MainWindow::changeSize(), LanguageChooser::checkBoxToggled(), QButtonGroupPrivate::detectCheckedButton(), Window::filterRegExpChanged(), MoviePlayer::fitToWindow(), getStyleOption(), Q3CheckTableItem::isChecked(), Screenshot::newScreenshot(), nextCheckState(), QDockWidgetTitleButton::paintEvent(), qdesigner_internal::OldSignalSlotDialog::populateSignalList(), qdesigner_internal::OldSignalSlotDialog::populateSlotList(), RegExpDialog::refresh(), Q3ButtonGroup::selected(), DetailsDialog::sendOffers(), Q3CheckTableItem::setContentFromEditor(), Screenshot::shootScreen(), qdesigner_internal::OldSignalSlotDialog::showAllSignalsSlots(), Window::sortChanged(), Window::textFilterChanged(), View::toggleAntialiasing(), View::toggleOpenGL(), AnimationSaveWidget::toggleRecord(), and ControllerWindow::updatePreview().
00737 { 00738 Q_D(const QAbstractButton); 00739 return d->checked; 00740 }
| void QAbstractButton::setDown | ( | bool | ) |
Definition at line 751 of file qabstractbutton.cpp.
References d.
Referenced by QFileDialogPrivate::_q_showDetails(), QFileDialogPrivate::_q_showList(), animateClick(), changeEvent(), QAccessibleToolButton::doAction(), QPushButton::focusOutEvent(), keyPressEvent(), mouseMoveEvent(), ColorButton::mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), QFileDialogPrivate::setupToolButtons(), and QPushButton::showMenu().
00752 { 00753 Q_D(QAbstractButton); 00754 if (d->down == down) 00755 return; 00756 d->down = down; 00757 d->refresh(); 00758 if (d->autoRepeat && d->down) 00759 d->repeatTimer.start(d->autoRepeatDelay, this); 00760 else 00761 d->repeatTimer.stop(); 00762 }
| bool QAbstractButton::isDown | ( | ) | const |
Definition at line 764 of file qabstractbutton.cpp.
References d.
Referenced by ColorButton::drawButton(), getStyleOption(), QToolBoxButton::paintEvent(), QDockWidgetTitleButton::paintEvent(), QCalToolButton::paintEvent(), QTableCornerButton::paintEvent(), and QFileDialogPrivate::viewMode().
00765 { 00766 Q_D(const QAbstractButton); 00767 return d->down; 00768 }
| void QAbstractButton::setAutoRepeat | ( | bool | ) |
Definition at line 781 of file qabstractbutton.cpp.
References d.
Referenced by QCalendarWidgetPrivate::createHeader(), QDesignerQ3WidgetStack::QDesignerQ3WidgetStack(), QDesignerStackedWidget::QDesignerStackedWidget(), and View::View().
00782 { 00783 Q_D(QAbstractButton); 00784 if (d->autoRepeat == autoRepeat) 00785 return; 00786 d->autoRepeat = autoRepeat; 00787 if (d->autoRepeat && d->down) 00788 d->repeatTimer.start(d->autoRepeatDelay, this); 00789 else 00790 d->repeatTimer.stop(); 00791 }
| bool QAbstractButton::autoRepeat | ( | ) | const |
Definition at line 793 of file qabstractbutton.cpp.
References d.
00794 { 00795 Q_D(const QAbstractButton); 00796 return d->autoRepeat; 00797 }
| void QAbstractButton::setAutoRepeatDelay | ( | int | ) |
Definition at line 810 of file qabstractbutton.cpp.
References d.
Referenced by View::View().
00811 { 00812 Q_D(QAbstractButton); 00813 d->autoRepeatDelay = autoRepeatDelay; 00814 }
| int QAbstractButton::autoRepeatDelay | ( | ) | const |
Definition at line 816 of file qabstractbutton.cpp.
References d.
00817 { 00818 Q_D(const QAbstractButton); 00819 return d->autoRepeatDelay; 00820 }
| void QAbstractButton::setAutoRepeatInterval | ( | int | ) |
Definition at line 833 of file qabstractbutton.cpp.
References d.
Referenced by View::View().
00834 { 00835 Q_D(QAbstractButton); 00836 d->autoRepeatInterval = autoRepeatInterval; 00837 }
| int QAbstractButton::autoRepeatInterval | ( | ) | const |
Definition at line 839 of file qabstractbutton.cpp.
References d.
00840 { 00841 Q_D(const QAbstractButton); 00842 return d->autoRepeatInterval; 00843 }
| void QAbstractButton::setAutoExclusive | ( | bool | ) |
Definition at line 864 of file qabstractbutton.cpp.
References d.
Referenced by qRadioButtonInit().
00865 { 00866 Q_D(QAbstractButton); 00867 d->autoExclusive = autoExclusive; 00868 }
| bool QAbstractButton::autoExclusive | ( | ) | const |
Definition at line 870 of file qabstractbutton.cpp.
References d.
00871 { 00872 Q_D(const QAbstractButton); 00873 return d->autoExclusive; 00874 }
| QButtonGroup * QAbstractButton::group | ( | ) | const |
Returns the group that this button belongs to.
If the button is not a member of any QButtonGroup, this function returns 0.
Definition at line 885 of file qabstractbutton.cpp.
References d.
Referenced by QButtonGroup::addButton(), and QButtonGroup::removeButton().
00886 { 00887 Q_D(const QAbstractButton); 00888 return d->group; 00889 }
| void QAbstractButton::setIconSize | ( | const QSize & | size | ) | [slot] |
Definition at line 1317 of file qabstractbutton.cpp.
References d, QWidget::isVisible(), QWidget::size(), QWidget::update(), and QWidget::updateGeometry().
Referenced by MoviePlayer::createButtons(), QToolBarPrivate::createItem(), SortingBox::createToolButton(), EditorWithReset::EditorWithReset(), ImageComposer::ImageComposer(), PathStrokeWidget::PathStrokeWidget(), QBalloonTip::QBalloonTip(), qdesigner_internal::RoleEditor::RoleEditor(), QWorkspacePrivate::showMaximizeControls(), and View::View().
01318 { 01319 Q_D(QAbstractButton); 01320 if (d->iconSize == size) 01321 return; 01322 01323 d->iconSize = size; 01324 updateGeometry(); 01325 if (isVisible()) { 01326 update(); 01327 } 01328 }
| void QAbstractButton::animateClick | ( | int | msec = 100 |
) | [slot] |
Performs an animated click: the button is pressed and released msec milliseconds later (the default is 100 ms).
All signals associated with a click are emitted as appropriate.
This function does nothing if the button is disabled.
Definition at line 903 of file qabstractbutton.cpp.
References d, QCoreApplication::flush(), QWidget::focusPolicy(), QWidget::isEnabled(), Qt::NoFocus, QWidget::repaint(), setDown(), and QWidget::setFocus().
Referenced by CompositionWidget::CompositionWidget(), QAccessibleTabBar::doAction(), QAccessibleButton::doAction(), event(), NewForm::on_treeWidget_itemActivated(), PathDeformWidget::PathDeformWidget(), GradientWidget::setDefault(), and XFormWidget::XFormWidget().
00904 { 00905 if (!isEnabled()) 00906 return; 00907 Q_D(QAbstractButton); 00908 if (d->checkable && focusPolicy() != Qt::NoFocus) 00909 setFocus(); 00910 setDown(true); 00911 repaint(); //flush paint event before invoking potentially expensive operation 00912 QApplication::flush(); 00913 d->emitPressed(); 00914 d->animateTimer.start(msec, this); 00915 }
| void QAbstractButton::click | ( | ) | [slot] |
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 is disabled.
Definition at line 929 of file qabstractbutton.cpp.
References d, QWidget::isEnabled(), and nextCheckState().
Referenced by QDialog::keyPressEvent(), QPushButton::keyPressEvent(), and QAbstractButtonPrivate::moveFocus().
00930 { 00931 if (!isEnabled()) 00932 return; 00933 Q_D(QAbstractButton); 00934 QPointer<QAbstractButton> guard(this); 00935 d->down = true; 00936 d->emitPressed(); 00937 if (guard) { 00938 d->down = false; 00939 nextCheckState(); 00940 if (guard) 00941 d->emitReleased(); 00942 if (guard) 00943 d->emitClicked(); 00944 } 00945 }
| void QAbstractButton::toggle | ( | ) | [slot] |
Toggles the state of a checkable button.
Definition at line 953 of file qabstractbutton.cpp.
References d, and setChecked().
00954 { 00955 Q_D(QAbstractButton); 00956 setChecked(!d->checked); 00957 }
| void QAbstractButton::setChecked | ( | bool | ) | [slot] |
Definition at line 701 of file qabstractbutton.cpp.
References checkStateSet(), d, emit, and toggled().
Referenced by AnimationSaveWidget::AnimationSaveWidget(), CompositionWidget::CompositionWidget(), Q3CheckTableItem::createEditor(), Window::createFirstExclusiveGroup(), MainWindow::createGroupBox(), Window::createIconGroupBox(), Window::createNonExclusiveGroup(), Window::createPushButtonGroup(), Window::createSecondExclusiveGroup(), WidgetGallery::createTopLeftGroupBox(), WidgetGallery::createTopRightGroupBox(), ControllerWindow::createTypeGroupBox(), LanguageChooser::eventFilter(), GradientWidget::GradientWidget(), LanguageChooser::hideAll(), nextCheckState(), PathDeformWidget::PathDeformWidget(), PathStrokeWidget::PathStrokeWidget(), PermissionsTab::PermissionsTab(), PrintPanel::PrintPanel(), RegExpDialog::RegExpDialog(), Q3CheckTableItem::setChecked(), QCheckBox::setCheckState(), QToolButton::setDefaultAction(), qdesigner_internal::OldSignalSlotDialog::setShowAllSignalsSlots(), qdesigner_internal::OldSignalSlotDialog::setSignalSlot(), LanguageChooser::showAll(), toggle(), MoviePlayer::updateButtons(), View::View(), WidgetGallery::WidgetGallery(), and XFormWidget::XFormWidget().
00702 { 00703 Q_D(QAbstractButton); 00704 if (!d->checkable || d->checked == checked) { 00705 if (!d->blockRefresh) 00706 checkStateSet(); 00707 return; 00708 } 00709 00710 if (!checked && d->queryCheckedButton() == this) { 00711 // the checked button of an exclusive or autoexclusive group cannot be unchecked 00712 #ifndef QT_NO_BUTTONGROUP 00713 if (d->group ? d->group->d_func()->exclusive : d->autoExclusive) 00714 return; 00715 if (d->group) 00716 d->group->d_func()->detectCheckedButton(); 00717 #else 00718 if (d->autoExclusive) 00719 return; 00720 #endif 00721 } 00722 00723 QPointer<QAbstractButton> guard(this); 00724 00725 d->checked = checked; 00726 if (!d->blockRefresh) 00727 checkStateSet(); 00728 d->refresh(); 00729 00730 if (guard && checked) 00731 d->notifyChecked(); 00732 if (guard) 00733 emit toggled(checked); 00734 }
| void QAbstractButton::pressed | ( | ) | [signal] |
This signal is emitted when the button is pressed down.
Referenced by QPushButton::setMenu().
| void QAbstractButton::released | ( | ) | [signal] |
| void QAbstractButton::clicked | ( | bool | checked = false |
) | [signal] |
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 when click() or animateClick() is called. Notably, this signal is not emitted if you call setDown(), setChecked() or toggle().
If the button is checkable, checked is true if the button is checked, or false if the button is unchecked.
Referenced by ColorButton::ColorButton(), qdesigner_internal::PaletteEditorButton::PaletteEditorButton(), qdesigner_internal::QtBrushButton::QtBrushButton(), qdesigner_internal::QtColorButton::QtColorButton(), qdesigner_internal::StringListEditorButton::StringListEditorButton(), and qdesigner_internal::StyledButton::StyledButton().
| void QAbstractButton::toggled | ( | bool | checked | ) | [signal] |
This signal is emitted whenever a checkable button changes its state. checked is true if the button is checked, or false if the button is unchecked.
This may be the result of a user action, click() slot activation, or because setChecked() was called.
The states of buttons in exclusive button groups are updated before this signal is emitted. This means that slots can act on either the "off" signal or the "on" signal emitted by the buttons in the group whose states have changed.
For example, a slot that reacts to signals emitted by newly checked buttons but which ignores signals from buttons that have been unchecked can be implemented using the following pattern:
void MyWidget::reactToToggle(bool checked) { if (checked) { // Examine the new button states. ... } }
Button groups can be created using the QButtonGroup class, and updates to the button states monitored with the {QButtonGroup::buttonClicked()} signal.
Referenced by setChecked().
| void QAbstractButton::paintEvent | ( | QPaintEvent * | e | ) | [protected, pure virtual] |
Reimplemented from QWidget.
| bool QAbstractButton::hitButton | ( | const QPoint & | pos | ) | const [protected, virtual] |
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 this function to provide support for clickable areas of different shapes and sizes.
Definition at line 991 of file qabstractbutton.cpp.
References QRect::contains(), QWidget::pos(), and QWidget::rect().
Referenced by QToolButton::hitButton(), mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().
Here is the call graph for this function:

| void QAbstractButton::checkStateSet | ( | ) | [protected, virtual] |
This virtual handler is called when setChecked() was called, unless it was called from within nextCheckState(). It allows subclasses to reset their intermediate button states.
Definition at line 966 of file qabstractbutton.cpp.
Referenced by setChecked().
| void QAbstractButton::nextCheckState | ( | ) | [protected, virtual] |
This virtual handler is called when a button is clicked. The default implementation calls setChecked(!isChecked()) if the button isCheckable(). It allows subclasses to implement intermediate button states.
Definition at line 977 of file qabstractbutton.cpp.
References isCheckable(), isChecked(), and setChecked().
Referenced by click(), QToolButton::nextCheckState(), QCheckBox::nextCheckState(), and QAbstractButtonPrivate::notifyChecked().
00978 { 00979 if (isCheckable()) 00980 setChecked(!isChecked()); 00981 }
Here is the call graph for this function:

| bool QAbstractButton::event | ( | QEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 997 of file qabstractbutton.cpp.
References animateClick(), QEvent::ContextMenu, d, QWidget::event(), QWidget::focusPolicy(), QEvent::HoverEnter, QEvent::HoverLeave, QEvent::HoverMove, QShortcutEvent::isAmbiguous(), QWidget::isEnabled(), QEvent::MouseButtonDblClick, QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseMove, Qt::NoFocus, QWidget::setAttribute(), QWidget::setFocus(), QEvent::Shortcut, QShortcutEvent::shortcutId(), QEvent::TabletMove, QEvent::TabletPress, QEvent::TabletRelease, QEvent::type(), Qt::WA_KeyboardFocusChange, QEvent::Wheel, and QWidget::window().
Referenced by QDockWidgetTitleButton::enterEvent(), QCheckBox::event(), QToolButton::event(), QRadioButton::event(), QPushButton::event(), and QDockWidgetTitleButton::leaveEvent().
00998 { 00999 // as opposed to other widgets, disabled buttons accept mouse 01000 // events. This avoids surprising click-through scenarios 01001 if (!isEnabled()) { 01002 switch(e->type()) { 01003 case QEvent::TabletPress: 01004 case QEvent::TabletRelease: 01005 case QEvent::TabletMove: 01006 case QEvent::MouseButtonPress: 01007 case QEvent::MouseButtonRelease: 01008 case QEvent::MouseButtonDblClick: 01009 case QEvent::MouseMove: 01010 case QEvent::HoverMove: 01011 case QEvent::HoverEnter: 01012 case QEvent::HoverLeave: 01013 case QEvent::ContextMenu: 01014 #ifndef QT_NO_WHEELEVENT 01015 case QEvent::Wheel: 01016 #endif 01017 return true; 01018 default: 01019 break; 01020 } 01021 } 01022 01023 #ifndef QT_NO_SHORTCUT 01024 if (e->type() == QEvent::Shortcut) { 01025 Q_D(QAbstractButton); 01026 QShortcutEvent *se = static_cast<QShortcutEvent *>(e); 01027 if (d->shortcutId != se->shortcutId()) 01028 return false; 01029 if (focusPolicy() != Qt::NoFocus) 01030 setFocus(); 01031 if (!se->isAmbiguous()) 01032 animateClick(); 01033 else 01034 window()->setAttribute(Qt::WA_KeyboardFocusChange); 01035 return true; 01036 } 01037 #endif 01038 return QWidget::event(e); 01039 }
Here is the call graph for this function:

| void QAbstractButton::keyPressEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1108 of file qabstractbutton.cpp.
References d, QCoreApplication::flush(), QWidget::focusNextPrevChild(), QWidget::hasFocus(), QEvent::ignore(), QKeyEvent::isAutoRepeat(), QKeyEvent::key(), Qt::Key_Down, Qt::Key_Enter, Qt::Key_Escape, Qt::Key_Left, Qt::Key_Return, Qt::Key_Right, Qt::Key_Select, Qt::Key_Space, Qt::Key_Up, next, QWidget::repaint(), and setDown().
Referenced by QPushButton::keyPressEvent().
01109 { 01110 Q_D(QAbstractButton); 01111 bool next = true; 01112 switch (e->key()) { 01113 case Qt::Key_Enter: 01114 case Qt::Key_Return: 01115 e->ignore(); 01116 break; 01117 case Qt::Key_Select: 01118 case Qt::Key_Space: 01119 if (!e->isAutoRepeat()) { 01120 setDown(true); 01121 repaint(); //flush paint event before invoking potentially expensive operation 01122 QApplication::flush(); 01123 d->emitPressed(); 01124 } 01125 break; 01126 case Qt::Key_Up: 01127 case Qt::Key_Left: 01128 next = false; 01129 // fall through 01130 case Qt::Key_Right: 01131 case Qt::Key_Down: 01132 #ifndef QT_NO_BUTTONGROUP 01133 if (d->group || d->autoExclusive) { 01134 #else 01135 if (d->autoExclusive) { 01136 #endif 01137 d->moveFocus(e->key()); 01138 if (hasFocus()) // nothing happend, propagate 01139 e->ignore(); 01140 } else { 01141 focusNextPrevChild(next); 01142 } 01143 break; 01144 case Qt::Key_Escape: 01145 if (d->down) { 01146 setDown(false); 01147 repaint(); //flush paint event before invoking potentially expensive operation 01148 QApplication::flush(); 01149 d->emitReleased(); 01150 break; 01151 } 01152 // fall through 01153 default: 01154 e->ignore(); 01155 } 01156 }
Here is the call graph for this function:

| void QAbstractButton::keyReleaseEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1159 of file qabstractbutton.cpp.
References d, QEvent::ignore(), QKeyEvent::isAutoRepeat(), QKeyEvent::key(), Qt::Key_Select, and Qt::Key_Space.
01160 { 01161 Q_D(QAbstractButton); 01162 switch (e->key()) { 01163 case Qt::Key_Select: 01164 case Qt::Key_Space: 01165 if (!e->isAutoRepeat() && d->down) 01166 d->click(); 01167 break; 01168 default: 01169 e->ignore(); 01170 } 01171 }
Here is the call graph for this function:

| void QAbstractButton::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1042 of file qabstractbutton.cpp.
References QEvent::accept(), QMouseEvent::button(), d, QCoreApplication::flush(), hitButton(), QEvent::ignore(), Qt::LeftButton, QMouseEvent::pos(), QWidget::repaint(), and setDown().
Referenced by QToolButton::mousePressEvent(), and ColorButton::mousePressEvent().
01043 { 01044 Q_D(QAbstractButton); 01045 if (e->button() != Qt::LeftButton) { 01046 e->ignore(); 01047 return; 01048 } 01049 if (hitButton(e->pos())) { 01050 setDown(true); 01051 repaint(); //flush paint event before invoking potentially expensive operation 01052 QApplication::flush(); 01053 d->emitPressed(); 01054 e->accept(); 01055 } else { 01056 e->ignore(); 01057 } 01058 }
Here is the call graph for this function:

| void QAbstractButton::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1061 of file qabstractbutton.cpp.
References QEvent::accept(), QMouseEvent::button(), d, hitButton(), QEvent::ignore(), Qt::LeftButton, QMouseEvent::pos(), and setDown().
Referenced by ColorButton::mouseReleaseEvent(), and QToolButton::mouseReleaseEvent().
01062 { 01063 Q_D(QAbstractButton); 01064 if (e->button() != Qt::LeftButton) { 01065 // clean up apperance if left button has been pressed 01066 if (d->down) 01067 setDown(false); 01068 e->ignore(); 01069 return; 01070 } 01071 01072 if (!d->down) 01073 return; 01074 01075 if (hitButton(e->pos())) { 01076 d->click(); 01077 e->accept(); 01078 } else { 01079 setDown(false); 01080 e->ignore(); 01081 } 01082 }
Here is the call graph for this function:

| void QAbstractButton::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1085 of file qabstractbutton.cpp.
References QEvent::accept(), QMouseEvent::buttons(), d, QCoreApplication::flush(), hitButton(), QEvent::ignore(), Qt::LeftButton, QMouseEvent::pos(), QWidget::repaint(), and setDown().
Referenced by QRadioButton::mouseMoveEvent(), and QCheckBox::mouseMoveEvent().
01086 { 01087 Q_D(QAbstractButton); 01088 if (!(e->buttons() & Qt::LeftButton)) { 01089 e->ignore(); 01090 return; 01091 } 01092 01093 if (hitButton(e->pos()) != d->down) { 01094 setDown(!d->down); 01095 repaint(); //flush paint event before invoking potentially expensive operation 01096 QApplication::flush(); 01097 if (d->down) 01098 d->emitPressed(); 01099 else 01100 d->emitReleased(); 01101 e->accept(); 01102 } else if (!hitButton(e->pos())) { 01103 e->ignore(); 01104 } 01105 }
Here is the call graph for this function:

| void QAbstractButton::focusInEvent | ( | QFocusEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1195 of file qabstractbutton.cpp.
References d, and QWidget::focusInEvent().
Referenced by QPushButton::focusInEvent().
01196 { 01197 Q_D(QAbstractButton); 01198 #ifdef QT_KEYPAD_NAVIGATION 01199 if (!QApplication::keypadNavigationEnabled()) 01200 #endif 01201 d->fixFocusPolicy(); 01202 QWidget::focusInEvent(e); 01203 }
Here is the call graph for this function:

| void QAbstractButton::focusOutEvent | ( | QFocusEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1206 of file qabstractbutton.cpp.
References d, QWidget::focusOutEvent(), Qt::PopupFocusReason, and QFocusEvent::reason().
Referenced by QPushButton::focusOutEvent().
01207 { 01208 Q_D(QAbstractButton); 01209 if (e->reason() != Qt::PopupFocusReason) 01210 d->down = false; 01211 QWidget::focusOutEvent(e); 01212 }
Here is the call graph for this function:

| void QAbstractButton::changeEvent | ( | QEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1215 of file qabstractbutton.cpp.
References QWidget::changeEvent(), QEvent::EnabledChange, QWidget::isEnabled(), setDown(), and QEvent::type().
Referenced by QToolButton::changeEvent().
01216 { 01217 // Q_D(QAbstractButton); 01218 switch (e->type()) { 01219 case QEvent::EnabledChange: 01220 if (!isEnabled()) 01221 setDown(false); 01222 break; 01223 default: 01224 break; 01225 } 01226 QWidget::changeEvent(e); 01227 }
Here is the call graph for this function:

| void QAbstractButton::timerEvent | ( | QTimerEvent * | e | ) | [protected, virtual] |
Reimplemented from QObject.
Definition at line 1175 of file qabstractbutton.cpp.
References d, and QTimerEvent::timerId().
Referenced by QToolButton::timerEvent().
01176 { 01177 Q_D(QAbstractButton); 01178 if (e->timerId() == d->repeatTimer.timerId()) { 01179 d->repeatTimer.start(d->autoRepeatInterval, this); 01180 if (d->down) { 01181 QPointer<QAbstractButton> guard(this); 01182 d->emitReleased(); 01183 if (guard) 01184 d->emitClicked(); 01185 if (guard) 01186 d->emitPressed(); 01187 } 01188 } else if (e->timerId() == d->animateTimer.timerId()) { 01189 d->animateTimer.stop(); 01190 d->click(); 01191 } 01192 }
Here is the call graph for this function:

friend class QButtonGroup [friend] |
Definition at line 153 of file qabstractbutton.h.
1.5.1