📄 qaction.cpp
字号:
/*! \property QAction::shortcutContext \brief the context for the action's shortcut Valid values for this property can be found in \l Qt::ShortcutContext. The default value is Qt::WindowShortcut.*/void QAction::setShortcutContext(Qt::ShortcutContext context){ Q_D(QAction); if (d->shortcutContext == context) return; QAPP_CHECK("setShortcutContext"); d->shortcutContext = context; d->redoGrab(qApp->d_func()->shortcutMap); d->redoGrabAlternate(qApp->d_func()->shortcutMap); d->sendDataChanged();}Qt::ShortcutContext QAction::shortcutContext() const{ Q_D(const QAction); return d->shortcutContext;}/*! \property QAction::autoRepeat \brief whether the action can auto repeat \since 4.2 If true, the action will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.*/void QAction::setAutoRepeat(bool on){ Q_D(QAction); if (d->autorepeat == on) return; QAPP_CHECK("setAutoRepeat"); d->autorepeat = on; d->redoGrab(qApp->d_func()->shortcutMap); d->redoGrabAlternate(qApp->d_func()->shortcutMap); d->sendDataChanged();}bool QAction::autoRepeat() const{ Q_D(const QAction); return d->autorepeat;}#endif // QT_NO_SHORTCUT/*! \property QAction::font \brief the action's font The font property is used to render the text set on the QAction. The font will can be considered a hint as it will not be consulted in all cases based upon application and style. \sa QAction::setText() QStyle*/void QAction::setFont(const QFont &font){ Q_D(QAction); if (d->font == font) return; d->fontSet = true; d->font = font; d->sendDataChanged();}QFont QAction::font() const{ Q_D(const QAction); return d->font;}#ifdef QT3_SUPPORT/*! Use one of the QAction constructors that doesn't take a \a name argument and call setObjectName() instead.*/QAction::QAction(QObject* parent, const char* name) : QObject(*(new QActionPrivate), parent){ Q_D(QAction); setObjectName(QString::fromAscii(name)); d->group = qobject_cast<QActionGroup *>(parent); if (d->group) d->group->addAction(this);}/*! Use one of the QAction constructors that doesn't take a \a name argument and call setObjectName() instead.*/QAction::QAction(const QString &text, const QKeySequence &shortcut, QObject* parent, const char* name) : QObject(*(new QActionPrivate), parent){ Q_D(QAction); setObjectName(QString::fromAscii(name)); d->text = text; setShortcut(shortcut); d->group = qobject_cast<QActionGroup *>(parent); if (d->group) d->group->addAction(this);}/*! Use one of the QAction constructors that doesn't take a \a name argument and call setObjectName() instead.*/QAction::QAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut, QObject* parent, const char* name) : QObject(*(new QActionPrivate), parent){ Q_D(QAction); setObjectName(QString::fromAscii(name)); d->text = text; setShortcut(shortcut); d->icon = icon; d->group = qobject_cast<QActionGroup *>(parent); if (d->group) d->group->addAction(this);}#endif/*! Destroys the object and frees allocated resources.*/QAction::~QAction(){ Q_D(QAction); for (int i = d->widgets.size()-1; i >= 0; --i) { QWidget *w = d->widgets.at(i); w->removeAction(this); } if (d->group) d->group->removeAction(this);#ifndef QT_NO_SHORTCUT if (d->shortcutId && qApp) { qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this); foreach (int id, d->alternateShortcutIds) qApp->d_func()->shortcutMap.removeShortcut(id, this); }#endif}/*! Sets this action group to \a group. The action will be automatically added to the group's list of actions. Actions within the group will be mutually exclusive. \sa QActionGroup, QAction::actionGroup()*/void QAction::setActionGroup(QActionGroup *group){ Q_D(QAction); if(group == d->group) return; if(d->group) d->group->removeAction(this); d->group = group; if(group) group->addAction(this);}/*! Returns the action group for this action. If no action group manages this action then 0 will be returned. \sa QActionGroup, QAction::setActionGroup()*/QActionGroup *QAction::actionGroup() const{ Q_D(const QAction); return d->group;}/*! \property QAction::icon \brief the action's icon In toolbars, the icon is used as the tool button icon; in menus, it is displayed to the left of the menu text. There is no default icon. If a null icon (QIcon::isNull() is passed into this function, the icon of the action is cleared.*/void QAction::setIcon(const QIcon &icon){ Q_D(QAction); d->icon = icon; d->sendDataChanged();}QIcon QAction::icon() const{ Q_D(const QAction); return d->icon;}#ifndef QT_NO_MENU/*! Returns the menu contained by this action. Actions that contain menus can be used to create menu items with submenus, or inserted into toolbars to create buttons with popup menus. \sa QMenu::addAction()*/QMenu *QAction::menu() const{ Q_D(const QAction); return d->menu;}/*! Sets the menu contained by this action to the specified \a menu.*/void QAction::setMenu(QMenu *menu){ Q_D(QAction); if (d->menu) d->menu->d_func()->setOverrideMenuAction(0); //we reset the default action of any previous menu d->menu = menu; if (menu) menu->d_func()->setOverrideMenuAction(this); d->sendDataChanged();}#endif // QT_NO_MENU/*! If \a b is true then this action will be considered a separator. How a separator is represented depends on the widget it is inserted into. Under most circumstances the text, submenu, and icon will be ignored for separator actions. \sa QAction::isSeparator()*/void QAction::setSeparator(bool b){ Q_D(QAction); if (d->separator == b) return; d->separator = b; d->sendDataChanged();}/*! Returns true if this action is a separator action; otherwise it returns false. \sa QAction::setSeparator()*/bool QAction::isSeparator() const{ Q_D(const QAction); return d->separator;}/*! \property QAction::text \brief the action's descriptive text If the action is added to a menu, the menu option will consist of the icon (if there is one), the text, and the shortcut (if there is one). If the text is not explicitly set in the constructor, or by using setText(), the action's description icon text will be used as text. There is no default text. \sa iconText*/void QAction::setText(const QString &text){ Q_D(QAction); if (d->text == text) return; d->text = text; d->sendDataChanged();}QString QAction::text() const{ Q_D(const QAction); QString s = d->text; if(s.isEmpty()) { s = d->iconText; s.replace(QLatin1Char('&'), QLatin1String("&&")); } return s;}/*! \property QAction::iconText \brief the action's descriptive icon text If QToolBar::toolButtonStyle is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button. It also serves as the default text in menus and tooltips if the action has not been defined with setText() or setToolTip(), and will also be used in toolbar buttons if no icon has been defined using setIcon(). If the icon text is not explicitly set, the action's normal text will be used for the icon text. There is no default icon text. \sa setToolTip(), setStatusTip()*/void QAction::setIconText(const QString &text){ Q_D(QAction); if (d->iconText == text) return; d->iconText = text; d->sendDataChanged();}QString QAction::iconText() const{ Q_D(const QAction); if (d->iconText.isEmpty()) return qt_strippedText(d->text); return d->iconText;}/*! \property QAction::toolTip \brief the action's tooltip This text is used for the tooltip. If no tooltip is specified, the action's text is used. \sa setStatusTip() setShortcut()*/void QAction::setToolTip(const QString &tooltip){ Q_D(QAction); if (d->tooltip == tooltip) return; d->tooltip = tooltip; d->sendDataChanged();}QString QAction::toolTip() const{ Q_D(const QAction); if (d->tooltip.isEmpty()) { if (!d->text.isEmpty()) return qt_strippedText(d->text); return d->iconText; } return d->tooltip;}/*! \property QAction::statusTip \brief the action's status tip The status tip is displayed on all status bars provided by the action's top-level parent widget. \sa setToolTip() showStatusText()*/void QAction::setStatusTip(const QString &statustip){ Q_D(QAction); if (d->statustip == statustip) return; d->statustip = statustip; d->sendDataChanged();}QString QAction::statusTip() const{ Q_D(const QAction); return d->statustip;}/*! \property QAction::whatsThis \brief the action's "What's This?" help text The "What's This?" text is used to provide a brief description of the action. The text may contain rich text. There is no default "What's This?" text. \sa QWhatsThis Q3StyleSheet*/void QAction::setWhatsThis(const QString &whatsthis){ Q_D(QAction); if (d->whatsthis == whatsthis) return; d->whatsthis = whatsthis; d->sendDataChanged();}QString QAction::whatsThis() const{ Q_D(const QAction); return d->whatsthis;}/*! \property QAction::checkable \brief whether the action is a checkable action A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -