QtBase
v6.3.1
|
The QAction class provides an abstraction for user commands that can be added to different user interface components. More...
#include <qaction.h>
Public Types | |
enum | MenuRole { NoRole = 0 , TextHeuristicRole , ApplicationSpecificRole , AboutQtRole , AboutRole , PreferencesRole , QuitRole } |
enum | Priority { LowPriority = 0 , NormalPriority = 128 , HighPriority = 256 } |
enum | ActionEvent { Trigger , Hover } |
Public Slots | |
void | trigger () |
void | hover () |
void | setChecked (bool) |
void | toggle () |
void | setEnabled (bool) |
void | resetEnabled () |
void | setDisabled (bool b) |
void | setVisible (bool) |
Public Slots inherited from QObject | |
void | deleteLater () |
Signals | |
void | changed () |
void | enabledChanged (bool enabled) |
void | checkableChanged (bool checkable) |
void | visibleChanged () |
void | triggered (bool checked=false) |
void | hovered () |
void | toggled (bool) |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Protected Member Functions | |
bool | event (QEvent *) override |
QAction (QActionPrivate &dd, QObject *parent) | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Properties | |
bool | checkable |
whether the action is a checkable action More... | |
bool | checked |
whether the action is checked. More... | |
bool | enabled |
whether the action is enabled More... | |
QIcon | icon |
the action's icon More... | |
QString | text |
the action's descriptive text More... | |
QString | iconText |
the action's descriptive icon text More... | |
QString | toolTip |
the action's tooltip More... | |
QString | statusTip |
the action's status tip More... | |
QString | whatsThis |
the action's "What's This?" help text More... | |
QFont | font |
the action's font More... | |
bool | visible |
whether the action can be seen (e.g. in menus and toolbars) More... | |
MenuRole | menuRole |
the action's menu role More... | |
bool | iconVisibleInMenu |
Whether or not an action should show an icon in a menu. More... | |
bool | shortcutVisibleInContextMenu |
Whether or not an action should show a shortcut in a context menu. More... | |
Priority | priority |
the actions's priority in the user interface. More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
Friends | |
class | QActionGroup |
class | QWidget |
class | QMenu |
class | QMenuPrivate |
class | QToolButton |
class | QGraphicsWidget |
The QAction class provides an abstraction for user commands that can be added to different user interface components.
\inmodule QtGui
In applications many common commands can be invoked via menus, toolbar buttons, and keyboard shortcuts. Since the user expects each command to be performed in the same way, regardless of the user interface used, it is useful to represent each command as an action.
Actions can be added to menus and toolbars, and will automatically keep them in sync. For example, in a word processor, if the user presses a Bold toolbar button, the Bold menu item will automatically be checked.
A QAction may contain an icon, menu text, a shortcut, status text, "What's This?" text, and a tooltip. Most of these can be set in the constructor. They can also be set independently with setIcon(), setText(), setIconText(), setShortcut(), setStatusTip(), setWhatsThis(), and setToolTip(). For menu items, it is possible to set an individual font with setFont().
We recommend that actions are created as children of the window they are used in. In most cases actions will be children of the application's main window.
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.
Enumerator | |
---|---|
Trigger | |
Hover |
enum QAction::MenuRole |
This enum describes how an action should be moved into the application menu on \macos.
\value NoRole This action should not be put into the application menu \value TextHeuristicRole This action should be put in the application menu based on the action's text as described in the QMenuBar documentation. \value ApplicationSpecificRole This action should be put in the application menu with an application specific role \value AboutQtRole This action handles the "About Qt" menu item. \value AboutRole This action should be placed where the "About" menu item is in the application menu. The text of the menu item will be set to "About <application name>". The application name is fetched from the {Info.plist} file in the application's bundle (See \l{Qt for macOS - Deployment}). \value PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu. \value QuitRole This action should be placed where the Quit menu item is in the application menu.
Setting this value only has effect on items that are in the immediate menus of the menubar, not the submenus of those menus. For example, if you have File menu in your menubar and the File menu has a submenu, setting the MenuRole for the actions in that submenu have no effect. They will never be moved.
Enumerator | |
---|---|
NoRole | |
TextHeuristicRole | |
ApplicationSpecificRole | |
AboutQtRole | |
AboutRole | |
PreferencesRole | |
QuitRole |
enum QAction::Priority |
This enum defines priorities for actions in user interface.
\value LowPriority The action should not be prioritized in the user interface.
\value NormalPriority
\value HighPriority The action should be prioritized in the user interface.
Enumerator | |
---|---|
LowPriority | |
NormalPriority | |
HighPriority |
Constructs an action with parent. If parent is an action group the action will be automatically inserted into the group.
Definition at line 265 of file qaction.cpp.
Constructs an action with some text and parent. If parent is an action group the action will be automatically inserted into the group.
The action uses a stripped version of text (e.g. "\&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description with setText(). The same text will be used for tooltips unless you specify a different text using setToolTip().
Definition at line 283 of file qaction.cpp.
Constructs an action with an icon and some text and parent. If parent is an action group the action will be automatically inserted into the group.
The action uses a stripped version of text (e.g. "\&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description with setText(). The same text will be used for tooltips unless you specify a different text using setToolTip().
Definition at line 302 of file qaction.cpp.
QAction::~QAction | ( | ) |
Destroys the object and frees allocated resources.
Definition at line 485 of file qaction.cpp.
|
protected |
QActionGroup * QAction::actionGroup | ( | ) | const |
Returns the action group for this action. If no action group manages this action, then \nullptr will be returned.
Definition at line 531 of file qaction.cpp.
void QAction::activate | ( | ActionEvent | event | ) |
Sends the relevant signals for ActionEvent event.
Action-based widgets use this API to cause the QAction to emit signals as well as emitting their own.
Definition at line 1112 of file qaction.cpp.
Definition at line 543 of file qaction.cpp.
|
signal |
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.
|
signal |
QVariant QAction::data | ( | ) | const |
Returns the user data as set in QAction::setData.
Definition at line 1086 of file qaction.cpp.
|
signal |
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Reimplemented in QWidgetAction.
Definition at line 1057 of file qaction.cpp.
QFont QAction::font | ( | ) | const |
Definition at line 475 of file qaction.cpp.
|
inlineslot |
|
signal |
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.
QIcon QAction::icon | ( | ) | const |
Definition at line 592 of file qaction.cpp.
QString QAction::iconText | ( | ) | const |
Definition at line 691 of file qaction.cpp.
bool QAction::isCheckable | ( | ) | const |
Definition at line 877 of file qaction.cpp.
bool QAction::isChecked | ( | ) | const |
bool QAction::isEnabled | ( | ) | const |
bool QAction::isIconVisibleInMenu | ( | ) | const |
bool QAction::isSeparator | ( | ) | const |
Returns true
if this action is a separator action; otherwise it returns false
.
Definition at line 623 of file qaction.cpp.
bool QAction::isShortcutVisibleInContextMenu | ( | ) | const |
bool QAction::isVisible | ( | ) | const |
QAction::MenuRole QAction::menuRole | ( | ) | const |
Definition at line 1220 of file qaction.cpp.
QAction::Priority QAction::priority | ( | ) | const |
Definition at line 837 of file qaction.cpp.
|
slot |
Definition at line 992 of file qaction.cpp.
void QAction::setActionGroup | ( | QActionGroup * | group | ) |
Sets this action group to group. The action will be automatically added to the group's list of actions.
Actions within the group will be mutually exclusive.
Definition at line 511 of file qaction.cpp.
void QAction::setCheckable | ( | bool | b | ) |
|
slot |
Sets the action's internal data to the given data.
Definition at line 1097 of file qaction.cpp.
|
inlineslot |
|
slot |
Definition at line 464 of file qaction.cpp.
Definition at line 681 of file qaction.cpp.
void QAction::setIconVisibleInMenu | ( | bool | visible | ) |
Definition at line 827 of file qaction.cpp.
void QAction::setSeparator | ( | bool | b | ) |
If 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.
Definition at line 607 of file qaction.cpp.
void QAction::setShortcutVisibleInContextMenu | ( | bool | show | ) |
Definition at line 710 of file qaction.cpp.
|
slot |
Definition at line 782 of file qaction.cpp.
Updates the relevant status bar for the UI represented by object by sending a QStatusTipEvent. 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.
Definition at line 766 of file qaction.cpp.
QString QAction::statusTip | ( | ) | const |
Definition at line 752 of file qaction.cpp.
QString QAction::text | ( | ) | const |
|
slot |
This is a convenience function for the \l checked property. Connect to it to change the checked state to its opposite state.
Definition at line 889 of file qaction.cpp.
|
signal |
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. As setChecked() changes the QAction, it emits changed() in addition to toggled().
checked is true if the action is checked, or false if the action is unchecked.
QString QAction::toolTip | ( | ) | const |
Definition at line 720 of file qaction.cpp.
|
inlineslot |
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 not emitted when setChecked() or toggle() is called.
If the action is checkable, checked is true if the action is checked, or false if the action is unchecked.
|
signal |
QString QAction::whatsThis | ( | ) | const |
Definition at line 792 of file qaction.cpp.
|
friend |
|
friend |
|
friend |
|
friend |
|
readwrite |
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 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.
|
readwrite |
|
readwrite |
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.
\uicontrol{What's This?} help on disabled actions is still available, provided that the QAction::whatsThis property is set.
An action will be disabled when all widgets to which it is added (with QWidget::addAction()) are disabled or not visible. When an action is disabled, it is not possible to trigger it through its shortcut.
By default, this property is true
(actions are enabled).
|
readwrite |
|
readwrite |
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.
|
readwrite |
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.
By default, this property contains an empty string.
|
readwrite |
Whether or not an action should show an icon in a menu.
In some applications, it may make sense to have actions with icons in the toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it is false, it is not shown.
The default is to follow whether the Qt::AA_DontShowIconsInMenus attribute is set for the application. Explicitly settings this property overrides the presence (or absence) of the attribute.
For example:
|
readwrite |
the action's menu role
This indicates what role the action serves in the application menu on \macos. By default all actions 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 \macos (usually just before the first application window is shown).
|
readwrite |
the actions's priority in the user interface.
This property can be set to indicate how the action should be prioritized in the user interface.
For instance, when toolbars have the Qt::ToolButtonTextBesideIcon mode set, then actions with LowPriority will not show the text labels.
|
readwrite |
Whether or not an action should show a shortcut in a context menu.
In some applications, it may make sense to have actions with shortcuts in context menus. If true, the shortcut (if valid) is shown when the action is shown via a context menu, when it is false, it is not shown.
The default is to follow whether the Qt::AA_DontShowShortcutsInContextMenus attribute is set for the application. Explicitly setting this property overrides the attribute.
|
readwrite |
the action's status tip
The status tip is displayed on all status bars provided by the action's top-level parent widget.
By default, this property contains an empty string.
|
readwrite |
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.
|
readwrite |
the action's tooltip
This text is used for the tooltip. If no tooltip is specified, the action's text is used.
By default, this property contains the action's text.
|
readwrite |
whether the action can be seen (e.g. in menus and toolbars)
If visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.
Actions which are not visible are not grayed out; they do not appear at all.
By default, this property is true
(actions are visible).
|
readwrite |
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.