CopperSpice API
1.9.2
|
Stores information about a process or command which can be added to a menu or a toolbar. More...
Public Types | |
enum | ActionEvent |
enum | MenuRole |
enum | Priority |
Public Signals | |
void | changed () |
void | hovered () |
void | toggled (bool isChecked) |
void | triggered (bool isChecked=false) |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Slots | |
void | hover () |
void | setChecked (bool isChecked) |
void | setDisabled (bool disabled) |
void | setEnabled (bool enabled) |
void | setVisible (bool visible) |
void | toggle () |
void | trigger () |
Public Slots inherited from QObject | |
void | deleteLater () |
Public Methods | |
QAction (const QIcon &icon, const QString &text, QObject *parent) | |
QAction (const QString &text, QObject *parent) | |
QAction (QObject *parent) | |
~QAction () | |
QActionGroup * | actionGroup () const |
void | activate (ActionEvent event) |
QList< QGraphicsWidget * > | associatedGraphicsWidgets () const |
QList< QWidget * > | associatedWidgets () const |
bool | autoRepeat () const |
QVariant | data () const |
QFont | font () const |
QIcon | icon () const |
QString | iconText () const |
bool | isCheckable () const |
bool | isChecked () const |
bool | isEnabled () const |
bool | isIconVisibleInMenu () const |
bool | isSeparator () const |
bool | isVisible () const |
QMenu * | menu () const |
MenuRole | menuRole () const |
QWidget * | parentWidget () const |
Priority | priority () const |
void | setActionGroup (QActionGroup *group) |
void | setAutoRepeat (bool repeat) |
void | setCheckable (bool isChecked) |
void | setData (const QVariant &data) |
void | setFont (const QFont &font) |
void | setIcon (const QIcon &icon) |
void | setIconText (const QString &text) |
void | setIconVisibleInMenu (bool visible) |
void | setMenu (QMenu *menu) |
void | setMenuRole (MenuRole menuRole) |
void | setPriority (Priority priority) |
void | setSeparator (bool separator) |
void | setShortcut (const QKeySequence &shortcut) |
void | setShortcutContext (Qt::ShortcutContext context) |
void | setShortcuts (const QList< QKeySequence > &shortcuts) |
void | setShortcuts (QKeySequence::StandardKey key) |
void | setStatusTip (const QString &statusTip) |
void | setText (const QString &text) |
void | setToolTip (const QString &tooltip) |
void | setWhatsThis (const QString &what) |
QKeySequence | shortcut () const |
Qt::ShortcutContext | shortcutContext () const |
QList< QKeySequence > | shortcuts () const |
bool | showStatusText (QWidget *widget=nullptr) |
QString | statusTip () const |
QString | text () const |
QString | toolTip () const |
QString | whatsThis () const |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Protected Methods | |
bool | event (QEvent *event) override |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Properties | |
autoRepeat | |
checkable | |
checked | |
enabled | |
font | |
icon | |
iconText | |
iconVisibleInMenu | |
menuRole | |
priority | |
shortcut | |
shortcutContext | |
statusTip | |
text | |
toolTip | |
visible | |
whatsThis | |
Properties inherited from QObject | |
objectName | |
Friends | |
class | QActionGroup |
class | QGraphicsWidget |
class | QMenu |
class | QMenuBar |
class | QToolButton |
class | QWidget |
Additional Inherited Members | |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QAction class stores information about a process or command which can be added to a menu or a toolbar. A QAction can have an icon, menu text, icon text, a shortcut, status text, "What's This?" text, and a tooltip. Most of these properties can be passed in the constructor. They can also be set by calling methods like setIcon(), setText(), setIconText(), setShortcut(), setStatusTip(), setWhatsThis(), and setToolTip().
Calling QAction::setFont() can be used to change the font for a specific action.
An action is added to a widget by calling methods like QMenu::addAction() or QGraphicsWidget::addAction().
Once a QAction has been created it can be added to any menu or toolbar. The action must be connected to the slot which will perform the required action. Actions should be created as children of the window they are used in. In most cases actions will be children of the application's main window.
If the same QAction is added to the menu and the toolbar and the action is checkable, then changing the status from menu will also change the status on the toolbar.
enum QAction::ActionEvent |
This enum type is used when calling QAction::activate()
Constant | Value | Description |
---|---|---|
QAction::Trigger | 0 | Emits the QAction::triggered() signal |
QAction::Hover | 1 | Emits the QAction::hovered() signal |
enum QAction::MenuRole |
This enum describes how an action should be moved into the application menu on Mac OS X.
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.
Constant | Value | Description |
---|---|---|
QAction::NoRole | 0 | This action should not be put into the application menu |
QAction::TextHeuristicRole | 1 | Action should be put in the application menu based on the action's text as described in the QMenuBar documentation. |
QAction::ApplicationSpecificRole | 2 | Action should be put in the application menu with an application specific role |
QAction::AboutCsRole | 3 | Action matches handles the "About CopperSpice" menu item. |
QAction::AboutRole | 4 | 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 YourAppName". The Application name is obtained from the Info.plist file located in the application bundle. |
QAction::PreferencesRole | 5 | Action should be placed where the "Preferences..." menu item is in the application menu. |
QAction::QuitRole | 6 | Action should be placed where the Quit menu item is in the application menu. |
enum QAction::Priority |
This enum defines priorities for actions in user interface.
Constant | Value | Description |
---|---|---|
QAction::LowPriority | 0 | The action should not be prioritized in the user interface. |
QAction::NormalPriority | 128 | |
QAction::HighPriority | 256 | The action should be prioritized in the user interface. |
|
explicit |
Constructs an action with parent. If the parent is an action group the action will be automatically inserted into the group.
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. For example, "&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().
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. For example, "&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().
QAction::~QAction | ( | ) |
Destroys the object and frees allocated resources.
QActionGroup * QAction::actionGroup | ( | ) | const |
Returns the action group for this action. If no action group manages this action then nullptr will be returned.
void QAction::activate | ( | QAction::ActionEvent | event | ) |
Emits the appropriate signals for the given event.
QList< QGraphicsWidget * > QAction::associatedGraphicsWidgets | ( | ) | const |
Returns a list of widgets this action has been added to.
Returns a list of widgets this action has been added to.
bool QAction::autoRepeat | ( | ) | const |
Returns the value of the property.
|
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.
QVariant QAction::data | ( | ) | const |
|
overrideprotectedvirtual |
Reimplemented from QObject::event()
Reimplemented in QWidgetAction::event()
QFont QAction::font | ( | ) | const |
Returns the value of the property.
|
inlineslot |
This method calls activate(Hover).
|
signal |
This signal is emitted when an action is highlighted by the user. For example, when the user hovers the cursor over a menu item or a toolbar object.
QIcon QAction::icon | ( | ) | const |
Returns the value of the property.
QString QAction::iconText | ( | ) | const |
Returns the value of the property.
bool QAction::isCheckable | ( | ) | const |
Returns the value of the property.
bool QAction::isChecked | ( | ) | const |
Returns the value of the property.
bool QAction::isEnabled | ( | ) | const |
Returns the value of the property.
bool QAction::isIconVisibleInMenu | ( | ) | const |
Returns the value of the property.
bool QAction::isSeparator | ( | ) | const |
Returns true if this action is a separator action, otherwise it returns false.
bool QAction::isVisible | ( | ) | const |
Returns the value of the property.
QMenu * QAction::menu | ( | ) | const |
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.
MenuRole QAction::menuRole | ( | ) | const |
Returns the value of the property.
QWidget * QAction::parentWidget | ( | ) | const |
Returns the parent widget.
Priority QAction::priority | ( | ) | const |
Returns the value of the property.
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.
void QAction::setAutoRepeat | ( | bool | repeat | ) |
Sets the value of the property to repeat.
void QAction::setCheckable | ( | bool | isChecked | ) |
Sets the value of the property to isChecked.
|
slot |
Sets the value of the property to isChecked.
void QAction::setData | ( | const QVariant & | data | ) |
Sets the action's internal data to the given data.
|
inlineslot |
This method sets the enabled property to the inverse of the given disabled. So if disabled is true the action is disabled, otherwise it is enabled.
|
slot |
Sets the value of the property to enabled.
void QAction::setFont | ( | const QFont & | font | ) |
Sets the value of the property to font.
void QAction::setIcon | ( | const QIcon & | icon | ) |
Sets the value of the property to icon.
void QAction::setIconText | ( | const QString & | text | ) |
Sets the value of the property to text.
void QAction::setIconVisibleInMenu | ( | bool | visible | ) |
Sets the value of the property to visible.
void QAction::setMenu | ( | QMenu * | menu | ) |
Sets the menu contained by this action to the specified menu.
void QAction::setPriority | ( | Priority | priority | ) |
Sets the value of the property to priority.
void QAction::setSeparator | ( | bool | separator | ) |
If separator 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.
void QAction::setShortcut | ( | const QKeySequence & | shortcut | ) |
Sets the value of the property to shortcut.
void QAction::setShortcutContext | ( | Qt::ShortcutContext | context | ) |
Sets the value of the property to context.
void QAction::setShortcuts | ( | const QList< QKeySequence > & | shortcuts | ) |
Sets shortcuts as the list of shortcuts that trigger the action. The first element of the list is the primary shortcut.
void QAction::setShortcuts | ( | QKeySequence::StandardKey | key | ) |
Sets a platform dependent list of shortcuts based on the key. The result of calling this method will depend on the currently running platform. More than one shortcut can assigned by this action. If only the primary shortcut is required use setShortcut instead.
void QAction::setStatusTip | ( | const QString & | statusTip | ) |
Sets the value of the property to statusTip. The property text is shown on the status bar when the mouse cursor enters the widget.
void QAction::setText | ( | const QString & | text | ) |
Sets the value of the property to text.
void QAction::setToolTip | ( | const QString & | tooltip | ) |
Sets the value of the property to toolTip.
|
slot |
Sets the value of the property to visible.
void QAction::setWhatsThis | ( | const QString & | what | ) |
Sets the value of the property to what.
QKeySequence QAction::shortcut | ( | ) | const |
Returns the value of the property.
Qt::ShortcutContext QAction::shortcutContext | ( | ) | const |
Returns the value of the property.
QList< QKeySequence > QAction::shortcuts | ( | ) | const |
Returns the list of shortcuts, with the primary shortcut as the first element of the list.
bool QAction::showStatusText | ( | QWidget * | widget = nullptr | ) |
Updates the relevant status bar for the 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.
QString QAction::text | ( | ) | const |
Returns the value of the property.
|
slot |
This method inverts the checked property.
|
signal |
This signal is emitted when a checkable action changes the checked property status. This can be the result of a user interaction or because setChecked() was called. The value for isChecked is true if the action is checked or false if the action is unchecked.
QString QAction::toolTip | ( | ) | const |
Returns the value of the property.
|
inlineslot |
This method calls activate(QAction::Trigger).
|
signal |
This signal is emitted when an action is activated by the user or when the trigger() method is called. For example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination. If the action is checkable then isChecked is true if the action is checked or false if the action is unchecked.
This signal is not emitted when setChecked() or toggle() is called.
QString QAction::whatsThis | ( | ) | const |
Returns the value of the property.
|
This property holds whether the action can auto repeat. 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.
Properties | Class Methods |
---|---|
read | autoRepeat |
write | setAutoRepeat |
notify | changed |
|
This property holds 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. 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.
By default, this property is false.
Properties | Class Methods |
---|---|
read | isCheckable |
write | setCheckable |
notify | changed |
|
This property holds whether the action is checked. Only checkable actions can be checked. By default, this is false and the action is unchecked.
Properties | Class Methods |
---|---|
read | isChecked |
write | setChecked |
|
This property holds whether the action is enabled.
Disabled actions can not 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. 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 and the action is enabled.
Properties | Class Methods |
---|---|
read | isEnabled |
write | setEnabled |
notify | changed |
|
This property holds 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.
By default, this property contains the application's default font.
Properties | Class Methods |
---|---|
read | font |
write | setFont |
notify | changed |
|
This property holds 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. If a null icon is passed to this method the icon for the action is cleared.
There is no default icon.
Properties | Class Methods |
---|---|
read | icon |
write | setIcon |
notify | changed |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | iconText |
write | setIconText |
notify | changed |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | isIconVisibleInMenu |
write | setIconVisibleInMenu |
notify | changed |
|
This property holds the action's menu role.
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 . 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).
Properties | Class Methods |
---|---|
read | menuRole |
write | setMenuRole |
notify | changed |
|
This property holds the action'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.
Properties | Class Methods |
---|---|
read | priority |
write | setPriority |
|
This property holds the action's primary shortcut key. Valid keycodes for this property can be found in Qt::Key and Qt::Modifier. There is no default shortcut key.
Properties | Class Methods |
---|---|
read | shortcut |
write | setShortcut |
notify | changed |
|
This property holds the context for the action's shortcut. Valid values for this property can be found in Qt::ShortcutContext. The default value is Qt::WindowShortcut.
Properties | Class Methods |
---|---|
read | shortcutContext |
write | setShortcutContext |
notify | changed |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | statusTip |
write | setStatusTip |
notify | changed |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | text |
write | setText |
notify | changed |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | toolTip |
write | setToolTip |
notify | changed |
|
This property holds whether the action can be seen. For example in menus and toolbars. If visible is true the action can be seen and chosen by the user. If visible is false the action can not 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).
Properties | Class Methods |
---|---|
read | isVisible |
write | setVisible |
notify | changed |
|
This property holds 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 text.
Properties | Class Methods |
---|---|
read | whatsThis |
write | setWhatsThis |
notify | changed |