📄 qaction.cpp
字号:
off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false. In some situations, the state of one toggle action should depend on the state of others. For example, "Left Align", "Center" and "Right Align" toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a QActionGroup with the QActionGroup::exclusive property set to true. \sa QAction::setChecked()*/void QAction::setCheckable(bool b){ Q_D(QAction); if (d->checkable == b) return; d->checkable = b; d->checked = false; d->sendDataChanged();}bool QAction::isCheckable() const{ Q_D(const QAction); return d->checkable;}/*! \fn void QAction::toggle() This is a convenience function for the \l checked property. Connect to it to change the checked state to its opposite state.*/void QAction::toggle(){ Q_D(QAction); setChecked(!d->checked);}/*! \property QAction::checked \brief whether the action is checked. Only checkable actions can be checked. By default, this is false (the action is unchecked). \sa checkable*/void QAction::setChecked(bool b){ Q_D(QAction); if (!d->checkable || d->checked == b) return; QPointer<QAction> guard(this); d->checked = b; d->sendDataChanged(); if (guard) emit toggled(b);}bool QAction::isChecked() const{ Q_D(const QAction); return d->checked;}/*! \fn void QAction::setDisabled(bool b) This is a convenience function for the \l enabled property, that is useful for signals--slots connections. If \a b is true the action is disabled; otherwise it is enabled.*//*! \property QAction::enabled \brief whether the action is enabled Disabled actions cannot be chosen by the user. They do not disappear from menus or toolbars, but they are displayed in a way which indicates that they are unavailable. For example, they might be displayed using only shades of gray. What's this? help on disabled actions is still available, provided that the QAction::whatsThis property is set.*/void QAction::setEnabled(bool b){ Q_D(QAction); if (b == d->enabled && b != d->forceDisabled) return; d->forceDisabled = !b; if (b && (!d->visible || (d->group && !d->group->isEnabled()))) return; QAPP_CHECK("setEnabled"); d->enabled = b;#ifndef QT_NO_SHORTCUT d->setShortcutEnabled(b, qApp->d_func()->shortcutMap);#endif d->sendDataChanged();}bool QAction::isEnabled() const{ Q_D(const QAction); return d->enabled;}/*! \property QAction::visible \brief whether the action can be seen (e.g. in menus and toolbars) If \e visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if \e visible is false the action cannot be seen or chosen by the user. Actions which are not visible are \e not grayed out; they do not appear at all.*/void QAction::setVisible(bool b){ Q_D(QAction); if (b == d->visible && b != d->forceInvisible) return; QAPP_CHECK("setVisible"); d->forceInvisible = !b; d->visible = b; d->enabled = b && !d->forceDisabled && (!d->group || d->group->isEnabled()) ;#ifndef QT_NO_SHORTCUT d->setShortcutEnabled(d->enabled, qApp->d_func()->shortcutMap);#endif d->sendDataChanged();}bool QAction::isVisible() const{ Q_D(const QAction); return d->visible;}/*! \reimp*/boolQAction::event(QEvent *e){#ifndef QT_NO_SHORTCUT if (e->type() == QEvent::Shortcut) { QShortcutEvent *se = static_cast<QShortcutEvent *>(e); Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()), "QAction::event", "Received shortcut event from incorrect shortcut"); if (se->isAmbiguous()) qWarning("QAction::eventFilter: Ambiguous shortcut overload: %s", QString(se->key()).toLatin1().constData()); else activate(Trigger); return true; }#endif return QObject::event(e);}/*! Returns the user data as set in QAction::setData. \sa setData()*/QVariantQAction::data() const{ Q_D(const QAction); return d->userData;}/*! \fn void QAction::setData(const QVariant &userData) Sets the action's internal data to the given \a userData. \sa data()*/voidQAction::setData(const QVariant &data){ Q_D(QAction); d->userData = data; d->sendDataChanged();}/*! Updates the relevant status bar for the \a widget specified by sending a QStatusTipEvent to its parent widget. Returns true if an event was sent; otherwise returns false. If a null widget is specified, the event is sent to the action's parent. \sa statusTip*/boolQAction::showStatusText(QWidget *widget){#ifdef QT_NO_STATUSTIP Q_UNUSED(widget);#else if(QObject *object = widget ? widget : parent()) { QStatusTipEvent tip(statusTip()); QApplication::sendEvent(object, &tip); return true; }#endif return false;}/*! Sends the relevant signals for ActionEvent \a event. Action based widgets use this API to cause the QAction to emit signals as well as emitting their own.*/void QAction::activate(ActionEvent event){ Q_D(QAction); if(event == Trigger) { QObject *guard = this; QMetaObject::addGuard(&guard); if(d->checkable) { // the checked action of an exclusive group cannot be unchecked if (d->checked && (d->group && d->group->isExclusive() && d->group->checkedAction() == this)) { QMetaObject::removeGuard(&guard); return; } setChecked(!d->checked); } if (guard) emit triggered(d->checked);#ifdef QT3_SUPPORT if (guard) emit activated(d->param);#endif QMetaObject::removeGuard(&guard); } else if(event == Hover) { emit hovered(); }}/*! \fn void QAction::triggered(bool checked) This signal is emitted when an action is activated by the user; for example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination, or when trigger() was called. Notably, it is \e not emitted when setChecked() or toggle() is called. If the action is checkable, \a checked is true if the action is checked, or false if the action is unchecked. \sa QAction::activate(), QAction::toggled(), checked*//*! \fn void QAction::toggled(bool checked) This signal is emitted whenever a checkable action changes its isChecked() status. This can be the result of a user interaction, or because setChecked() was called. \a checked is true if the action is checked, or false if the action is unchecked. \sa QAction::activate(), QAction::triggered(), checked*//*! \fn void QAction::hovered() This signal is emitted when an action is highlighted by the user; for example, when the user pauses with the cursor over a menu option, toolbar button, or presses an action's shortcut key combination. \sa QAction::activate()*//*! \fn void QAction::changed() This signal is emitted when an action has changed. If you are only interested in actions in a given widget, you can watch for QWidget::actionEvent() sent with an QEvent::ActionChanged. \sa QWidget::actionEvent()*//*! \enum QAction::ActionEvent This enum type is used when calling QAction::activate() \value Trigger this will cause the QAction::triggered() signal to be emitted. \value Hover this will cause the QAction::hovered() signal to be emitted.*//*! \fn void QAction::setMenuText(const QString &text) Use setText() instead.*//*! \fn QString QAction::menuText() const Use text() instead.*//*! \fn bool QAction::isOn() const Use isChecked() instead.*//*! \fn void QAction::setOn(bool b) Use setChecked() instead.*//*! \fn bool QAction::isToggleAction() const Use isCheckable() instead.*//*! \fn void QAction::setToggleAction(bool b) Use setCheckable() instead.*//*! \fn void QAction::setIconSet(const QIcon &i) Use setIcon() instead.*//*! \fn bool QAction::addTo(QWidget *w) Use QWidget::addAction() instead. \oldcode action->addTo(widget); \newcode widget->addAction(action); \endcode*//*! \fn bool QAction::removeFrom(QWidget *w) Use QWidget::removeAction() instead. \oldcode action->removeFrom(widget); \newcode widget->removeAction(action); \endcode*//*! \fn void QAction::setAccel(const QKeySequence &shortcut) Use setShortcut() instead.*//*! \fn QIcon QAction::iconSet() const Use icon() instead.*//*! \fn QKeySequence QAction::accel() const Use shortcut() instead.*//*! \fn void QAction::activated(int i); Use triggered() instead.*//*! \property QAction::menuRole \brief the action's menu role \since 4.2 This indicates what role the action serves in the application menu on Mac OS X. By default all action have the TextHeuristicRole, which means that the action is added based on its text (see QMenuBar for more information). The menu role can only be changed before the actions are put into the menu bar in Mac OS X (usually just before the first application window is shown).*/void QAction::setMenuRole(MenuRole menuRole){ Q_D(QAction); if (d->menuRole == menuRole) return; d->menuRole = menuRole; d->sendDataChanged();}QAction::MenuRole QAction::menuRole() const{ Q_D(const QAction); return d->menuRole;}#include "moc_qaction.cpp"#endif // QT_NO_ACTION
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -