CopperSpice API  1.8.1
QAction Class Reference

Stores information about a process or command which can be added to a menu or a toolbar. More...

Inheritance diagram for QAction:

## Public Types

enum  ActionEvent

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 ()

QActionGroupactionGroup () 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 isSeparator () const

bool isVisible () const

QWidgetparentWidget () 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 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< QKeySequenceshortcuts () 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< QStringdynamicPropertyNames () const

virtual bool eventFilter (QObject *watched, QEvent *event)

template<typename T >
findChild (const QString &childName=QString ()) const

template<class T >
QList< T > findChildren (const QRegularExpression &regExp, 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 QMetaObjectmetaObject () const

QString objectName () const

QObject * parent () const

template<class T = QVariant>
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)

## 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

priority

shortcut

shortcutContext

statusTip

text

toolTip

visible

whatsThis

Properties inherited from QObject
objectName

## Friends

class QActionGroup

class QGraphicsWidget

class QToolButton

class QWidget

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 QMetaObjectstaticMetaObject ()

static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())

## Detailed Description

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.

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.

### Example

QAction *openFile = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
openFile->setShortcuts(QKeySequence::Open);
openFile->setStatusTip(tr("Open an existing file"));
connect(openFile, &QAction::triggered, this, &MyMainWIndow::open);

## Member Enumeration Documentation

 enum QAction::ActionEvent

This enum type is used when calling QAction::activate()

ConstantValueDescription
QAction::Trigger 0 Emits the QAction::triggered() signal
QAction::Hover 1 Emits the QAction::hovered() signal

This enum describes how an action should be moved into the application menu on Mac OS X.

ConstantValueDescription
QAction::NoRole 0This 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::AboutCsRole3 Action matches handles the "About CopperSpice" menu item.
QAction::AboutRole4 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::PreferencesRole5 Action should be placed where the "Preferences..." menu item is in the application menu.
QAction::QuitRole6 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.

ConstantValueDescription
QAction::LowPriority 0The action should not be prioritized in the user interface.
QAction::NormalPriority 128
QAction::HighPriority 256The action should be prioritized in the user interface.
priority

## Constructor & Destructor Documentation

 QAction::QAction ( QObject * parent )
explicit

Constructs an action with parent. If the parent is an action group the action will be automatically inserted into the group.

 QAction::QAction ( const QString & text, QObject * parent )

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().

 QAction::QAction ( const QIcon & icon, const QString & text, QObject * parent )

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.

## Method Documentation

 QActionGroup * QAction::actionGroup ( ) const

Returns the action group for this action. If no action group manages this action then nullptr will be returned.

QActionGroup, QAction::setActionGroup()
 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.

 QList< QWidget * > QAction::associatedWidgets ( ) const

Returns a list of widgets this action has been added to.

 bool QAction::autoRepeat ( ) const

Returns the value of the property.

 void QAction::changed ( )
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.

QWidget::actionEvent()
 QVariant QAction::data ( ) const

Returns the user data which was set in setData().

setData()
 bool QAction::event ( QEvent * event )
overrideprotectedvirtual

Reimplemented from QObject::event()

Reimplemented in QWidgetAction::event()

 QFont QAction::font ( ) const

Returns the value of the property.

 void QAction::hover ( )
inlineslot

This method calls activate(Hover).

 void QAction::hovered ( )
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.

QAction::activate()
 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.

Returns the value of the property.

 bool QAction::isSeparator ( ) const

Returns true if this action is a separator action, otherwise it returns false.

QAction::setSeparator()
 bool QAction::isVisible ( ) const

Returns the value of the property.

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.

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.

QActionGroup, QAction::actionGroup()
 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.

 void QAction::setChecked ( bool 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.

data()
 void QAction::setDisabled ( bool disabled )
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.

 void QAction::setEnabled ( bool 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.

Sets the value of the property to menuRole.

 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.

QAction::isSeparator()
 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.

shortcuts(), 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.

QKeySequence::keyBindings()
 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.

 void QAction::setVisible ( bool visible )
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.

setShortcuts()
 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.

statusTip
 QString QAction::statusTip ( ) const

Returns the value of the statusTip property.

 QString QAction::text ( ) const

Returns the value of the property.

 void QAction::toggle ( )
slot

This method inverts the checked property.

 void QAction::toggled ( bool isChecked )
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.

QAction::activate(), QAction::triggered(), checked
 QString QAction::toolTip ( ) const

Returns the value of the property.

 void QAction::trigger ( )
inlineslot

This method calls activate(QAction::Trigger).

 void QAction::triggered ( bool isChecked = false )
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.

QAction::activate(), QAction::toggled(), checked
 QString QAction::whatsThis ( ) const

Returns the value of the property.

## Property Documentation

 QAction::autoRepeat

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.

PropertiesClass Methods
write setAutoRepeat
notify changed
 QAction::checkable

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.

QAction::setChecked()
PropertiesClass Methods
write setCheckable
notify changed
 QAction::checked

This property holds whether the action is checked. Only checkable actions can be checked. By default, this is false and the action is unchecked.

checkable
PropertiesClass Methods
write setChecked
 QAction::enabled

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.

text
PropertiesClass Methods
write setEnabled
notify changed
 QAction::font

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.

QAction::setText(), QStyle
PropertiesClass Methods
write setFont
notify changed
 QAction::icon

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.

PropertiesClass Methods
write setIcon
notify changed
 QAction::iconText

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.

setToolTip(), setStatusTip()
PropertiesClass Methods
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.

QApplication app(argc, argv);
QAction *myAction = new QAction();
myAction->setIcon(SomeIcon);
QAction::icon, QApplication::setAttribute()
PropertiesClass Methods
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).

PropertiesClass Methods
notify changed
 QAction::priority

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.

PropertiesClass Methods
write setPriority
 QAction::shortcut

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.

PropertiesClass Methods
write setShortcut
notify changed
 QAction::shortcutContext

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.

PropertiesClass Methods
write setShortcutContext
notify changed
 QAction::statusTip

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.

setToolTip(), showStatusText()
PropertiesClass Methods
write setStatusTip
notify changed
 QAction::text

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.

iconText
PropertiesClass Methods
write setText
notify changed
 QAction::toolTip

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.

setStatusTip(), setShortcut()
PropertiesClass Methods
write setToolTip
notify changed
 QAction::visible

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).

PropertiesClass Methods
write setVisible
notify changed
 QAction::whatsThis

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.

PropertiesClass Methods