📄 qabstractbutton.cpp
字号:
if (guard) d->emitClicked(); }}/*! \fn void QAbstractButton::toggle() Toggles the state of a checkable button. \sa checked*/void QAbstractButton::toggle(){ Q_D(QAbstractButton); setChecked(!d->checked);}/*! This virtual handler is called when setChecked() was called,unless it was called from within nextCheckState(). It allowssubclasses to reset their intermediate button states.\sa nextCheckState() */void QAbstractButton::checkStateSet(){}/*! This virtual handler is called when a button is clicked. Thedefault implementation calls setChecked(!isChecked()) if the buttonisCheckable(). It allows subclasses to implement intermediate buttonstates.\sa checkStateSet()*/void QAbstractButton::nextCheckState(){ if (isCheckable()) setChecked(!isChecked());}/*!Returns true if \a pos is inside the clickable button rectangle;otherwise returns false.By default, the clickable area is the entire widget. Subclassesmay reimplement this function to provide support for clickableareas of different shapes and sizes.*/bool QAbstractButton::hitButton(const QPoint &pos) const{ return rect().contains(pos);}/*! \reimp */bool QAbstractButton::event(QEvent *e){ // as opposed to other widgets, disabled buttons accept mouse // events. This avoids surprising click-through scenarios if (!isEnabled()) { switch(e->type()) { case QEvent::TabletPress: case QEvent::TabletRelease: case QEvent::TabletMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: case QEvent::HoverMove: case QEvent::HoverEnter: case QEvent::HoverLeave: case QEvent::ContextMenu:#ifndef QT_NO_WHEELEVENT case QEvent::Wheel:#endif return true; default: break; } }#ifndef QT_NO_SHORTCUT if (e->type() == QEvent::Shortcut) { Q_D(QAbstractButton); QShortcutEvent *se = static_cast<QShortcutEvent *>(e); if (d->shortcutId != se->shortcutId()) return false; if (!se->isAmbiguous()) { if (!d->animateTimer.isActive()) animateClick(); } else { if (focusPolicy() != Qt::NoFocus) setFocus(Qt::ShortcutFocusReason); window()->setAttribute(Qt::WA_KeyboardFocusChange); } return true; }#endif return QWidget::event(e);}/*! \reimp */void QAbstractButton::mousePressEvent(QMouseEvent *e){ Q_D(QAbstractButton); if (e->button() != Qt::LeftButton) { e->ignore(); return; } if (hitButton(e->pos())) { setDown(true); repaint(); //flush paint event before invoking potentially expensive operation QApplication::flush(); d->emitPressed(); e->accept(); } else { e->ignore(); }}/*! \reimp */void QAbstractButton::mouseReleaseEvent(QMouseEvent *e){ Q_D(QAbstractButton); if (e->button() != Qt::LeftButton) { e->ignore(); return; } if (!d->down) { e->ignore(); return; } if (hitButton(e->pos())) { d->repeatTimer.stop(); d->click(); e->accept(); } else { setDown(false); e->ignore(); }}/*! \reimp */void QAbstractButton::mouseMoveEvent(QMouseEvent *e){ Q_D(QAbstractButton); if (!(e->buttons() & Qt::LeftButton)) { e->ignore(); return; } if (hitButton(e->pos()) != d->down) { setDown(!d->down); repaint(); //flush paint event before invoking potentially expensive operation QApplication::flush(); if (d->down) d->emitPressed(); else d->emitReleased(); e->accept(); } else if (!hitButton(e->pos())) { e->ignore(); }}/*! \reimp */void QAbstractButton::keyPressEvent(QKeyEvent *e){ Q_D(QAbstractButton); bool next = true; switch (e->key()) { case Qt::Key_Enter: case Qt::Key_Return: e->ignore(); break; case Qt::Key_Select: case Qt::Key_Space: if (!e->isAutoRepeat()) { setDown(true); repaint(); //flush paint event before invoking potentially expensive operation QApplication::flush(); d->emitPressed(); } break; case Qt::Key_Up: case Qt::Key_Left: next = false; // fall through case Qt::Key_Right: case Qt::Key_Down:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)) { e->ignore(); return; }#endif#ifndef QT_NO_BUTTONGROUP if (d->group || d->autoExclusive) {#else if (d->autoExclusive) {#endif d->moveFocus(e->key()); if (hasFocus()) // nothing happend, propagate e->ignore(); } else { focusNextPrevChild(next); } break; case Qt::Key_Escape: if (d->down) { setDown(false); repaint(); //flush paint event before invoking potentially expensive operation QApplication::flush(); d->emitReleased(); break; } // fall through default: e->ignore(); }}/*! \reimp */void QAbstractButton::keyReleaseEvent(QKeyEvent *e){ Q_D(QAbstractButton); if (!e->isAutoRepeat()) d->repeatTimer.stop(); switch (e->key()) { case Qt::Key_Select: case Qt::Key_Space: if (!e->isAutoRepeat() && d->down) d->click(); break; default: e->ignore(); }}/*!\reimp */void QAbstractButton::timerEvent(QTimerEvent *e){ Q_D(QAbstractButton); if (e->timerId() == d->repeatTimer.timerId()) { d->repeatTimer.start(d->autoRepeatInterval, this); if (d->down) { QPointer<QAbstractButton> guard(this); d->emitReleased(); if (guard) d->emitClicked(); if (guard) d->emitPressed(); } } else if (e->timerId() == d->animateTimer.timerId()) { d->animateTimer.stop(); d->click(); }}/*! \reimp */void QAbstractButton::focusInEvent(QFocusEvent *e){ Q_D(QAbstractButton);#ifdef QT_KEYPAD_NAVIGATION if (!QApplication::keypadNavigationEnabled())#endif d->fixFocusPolicy(); QWidget::focusInEvent(e);}/*! \reimp */void QAbstractButton::focusOutEvent(QFocusEvent *e){ Q_D(QAbstractButton); if (e->reason() != Qt::PopupFocusReason) d->down = false; QWidget::focusOutEvent(e);}/*! \reimp */void QAbstractButton::changeEvent(QEvent *e){ Q_D(QAbstractButton); switch (e->type()) { case QEvent::EnabledChange: if (!isEnabled()) setDown(false); break; default: d->sizeHint = QSize(); break; } QWidget::changeEvent(e);}/*! \fn void QAbstractButton::paintEvent(QPaintEvent *e) \reimp*//*! \fn void QAbstractButton::pressed() This signal is emitted when the button is pressed down. \sa released(), clicked()*//*! \fn void QAbstractButton::released() This signal is emitted when the button is released. \sa pressed(), clicked(), toggled()*//*!\fn void QAbstractButton::clicked(bool checked)This signal is emitted when the button is activated (i.e. pressed downthen released while the mouse cursor is inside the button), when theshortcut key is typed, or when click() or animateClick() is called.Notably, this signal is \e not emitted if you call setDown(),setChecked() or toggle().If the button is checkable, \a checked is true if the button ischecked, or false if the button is unchecked.\sa pressed(), released(), toggled()*//*!\fn void QAbstractButton::toggled(bool checked)This signal is emitted whenever a checkable button changes its state.\a checked is true if the button is checked, or false if the button isunchecked.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 thissignal is emitted. This means that slots can act on either the "off"signal or the "on" signal emitted by the buttons in the group whosestates have changed.For example, a slot that reacts to signals emitted by newly checkedbuttons but which ignores signals from buttons that have been uncheckedcan be implemented using the following pattern:\codevoid MyWidget::reactToToggle(bool checked){ if (checked) { // Examine the new button states. ... }}\endcodeButton groups can be created using the QButtonGroup class, andupdates to the button states monitored with the\l{QButtonGroup::buttonClicked()} signal.\sa checked, clicked()*//*! \property QAbstractButton::iconSize \brief 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.*/QSize QAbstractButton::iconSize() const{ Q_D(const QAbstractButton); if (d->iconSize.isValid()) return d->iconSize; int e = style()->pixelMetric(QStyle::PM_ButtonIconSize); return QSize(e, e);}void QAbstractButton::setIconSize(const QSize &size){ Q_D(QAbstractButton); if (d->iconSize == size) return; d->iconSize = size; d->sizeHint = QSize(); updateGeometry(); if (isVisible()) { update(); }}#ifdef QT3_SUPPORT/*! Use icon() instead.*/QIcon *QAbstractButton::iconSet() const{ Q_D(const QAbstractButton); if (!d->icon.isNull()) return const_cast<QIcon *>(&d->icon); return 0;}/*! Use QAbstractButton(QWidget *) instead. Call setObjectName() if you want to specify an object name, and setParent() if you want to set the window flags.*/QAbstractButton::QAbstractButton(QWidget *parent, const char *name, Qt::WindowFlags f) : QWidget(*new QAbstractButtonPrivate, parent, f){ Q_D(QAbstractButton); setObjectName(QString::fromAscii(name)); d->init();}/*! \fn bool QAbstractButton::isOn() const Use isChecked() instead.*//*! \fn QPixmap *QAbstractButton::pixmap() const This compatibility function always returns 0. Use icon() instead.*//*! \fn void QAbstractButton::setPixmap(const QPixmap &p) Use setIcon() instead.*//*! \fn void QAbstractButton::setIconSet(const QIcon &icon) Use setIcon() instead.*//*! \fn void QAbstractButton::setOn(bool b) Use setChecked() instead.*//*! \fn bool QAbstractButton::isToggleButton() const Use isCheckable() instead.*//*! \fn void QAbstractButton::setToggleButton(bool b) Use setCheckable() instead.*//*! \fn void QAbstractButton::setAccel(const QKeySequence &key) Use setShortcut() instead.*//*! \fn QKeySequence QAbstractButton::accel() const Use shortcut() instead.*/#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -