Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | Properties | Friends | List of all members
QAction Class Reference

The QAction class provides an abstract user interface action that can be inserted into widgets. More...

#include <qaction.h>

Inheritance diagram for QAction:
QObject QDecorationAction QUndoAction QWhatsThisAction QWidgetAction

Public Types

enum  ActionEvent { Trigger, Hover }
 This enum type is used when calling QAction::activate() More...
 
enum  MenuRole {
  NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
  AboutRole, PreferencesRole, QuitRole
}
 This enum describes how an action should be moved into the application menu on Mac OS X. More...
 
enum  Priority { LowPriority = 0, NormalPriority = 128, HighPriority = 256 }
 This enum defines priorities for actions in user interface. More...
 
enum  SoftKeyRole { NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey }
 This enum describes how an action should be placed in the softkey bar. More...
 

Public Slots

void hover ()
 This is a convenience slot that calls activate(Hover). More...
 
void setChecked (bool)
 
void setDisabled (bool b)
 This is a convenience function for the enabled property, that is useful for signals–slots connections. More...
 
void setEnabled (bool)
 
void setVisible (bool)
 
void toggle ()
 This is a convenience function for the checked property. More...
 
void trigger ()
 This is a convenience slot that calls activate(Trigger). More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void changed ()
 This signal is emitted when an action has changed. More...
 
void 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. More...
 
void toggled (bool)
 This signal is emitted whenever a checkable action changes its isChecked() status. More...
 
void triggered (bool checked=false)
 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. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

QActionGroupactionGroup () const
 Returns the action group for this action. More...
 
void activate (ActionEvent event)
 Sends the relevant signals for ActionEvent event. More...
 
QList< QGraphicsWidget * > associatedGraphicsWidgets () const
 Returns a list of widgets this action has been added to. More...
 
QList< QWidget * > associatedWidgets () const
 Returns a list of widgets this action has been added to. More...
 
bool autoRepeat () const
 
QVariant data () const
 Returns the user data as set in QAction::setData. More...
 
QFont font () const
 
QIcon icon () const
 
QString iconText () const
 
bool isCheckable () const
 
bool isChecked () const
 
bool isEnabled () const
 
bool isIconVisibleInMenu () const
 
bool isSeparator () const
 Returns true if this action is a separator action; otherwise it returns false. More...
 
bool isVisible () const
 
QMenumenu () const
 Returns the menu contained by this action. More...
 
MenuRole menuRole () const
 
QWidgetparentWidget () const
 Returns the parent widget. More...
 
Priority priority () const
 
 QAction (QObject *parent)
 Constructs an action with parent. More...
 
 QAction (const QString &text, QObject *parent)
 Constructs an action with some text and parent. More...
 
 QAction (const QIcon &icon, const QString &text, QObject *parent)
 Constructs an action with an icon and some text and parent. More...
 
void setActionGroup (QActionGroup *group)
 Sets this action group to group. More...
 
void setAutoRepeat (bool)
 
void setCheckable (bool)
 
void setData (const QVariant &var)
 Sets the action's internal data to the given userData. More...
 
void setFont (const QFont &font)
 
void setIcon (const QIcon &icon)
 
void setIconText (const QString &text)
 
void setIconVisibleInMenu (bool visible)
 
void setMenu (QMenu *menu)
 Sets the menu contained by this action to the specified menu. More...
 
void setMenuRole (MenuRole menuRole)
 
void setPriority (Priority priority)
 
void setSeparator (bool b)
 If b is true then this action will be considered a separator. More...
 
void setShortcut (const QKeySequence &shortcut)
 
void setShortcutContext (Qt::ShortcutContext context)
 
void setShortcuts (const QList< QKeySequence > &shortcuts)
 Sets shortcuts as the list of shortcuts that trigger the action. More...
 
void setShortcuts (QKeySequence::StandardKey)
 Sets a platform dependent list of shortcuts based on the key. More...
 
void setSoftKeyRole (SoftKeyRole softKeyRole)
 
void setStatusTip (const QString &statusTip)
 
void setText (const QString &text)
 
void setToolTip (const QString &tip)
 
void setWhatsThis (const QString &what)
 
QKeySequence shortcut () const
 
Qt::ShortcutContext shortcutContext () const
 
QList< QKeySequenceshortcuts () const
 Returns the list of shortcuts, with the primary shortcut as the first element of the list. More...
 
bool showStatusText (QWidget *widget=0)
 Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent widget. More...
 
SoftKeyRole softKeyRole () const
 
QString statusTip () const
 
QString text () const
 
QString toolTip () const
 
QString whatsThis () const
 
 ~QAction ()
 Destroys the object and frees allocated resources. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

bool event (QEvent *)
 Reimplemented Function More...
 
 QAction (QActionPrivate &dd, QObject *parent)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Properties

bool autoRepeat
 whether the action can auto repeat More...
 
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...
 
QFont font
 the action's font More...
 
QIcon icon
 the action's icon More...
 
QString iconText
 the action's descriptive icon text More...
 
bool iconVisibleInMenu
 Whether or not an action should show an icon in a menu. More...
 
MenuRole menuRole
 the action's menu role More...
 
Priority priority
 the actions's priority in the user interface. More...
 
QKeySequence shortcut
 the action's primary shortcut key More...
 
Qt::ShortcutContext shortcutContext
 the context for the action's shortcut More...
 
SoftKeyRole softKeyRole
 the action's softkey role More...
 
QString statusTip
 the action's status tip More...
 
QString text
 the action's descriptive text More...
 
QString toolTip
 the action's tooltip More...
 
bool visible
 whether the action can be seen (e.g. More...
 
QString whatsThis
 the action's "What's This?" help text More...
 

Friends

class QActionGroup
 
class QGraphicsWidget
 
class QMenu
 
class QMenuBar
 
class QMenuPrivate
 
class QShortcutMap
 
void qt_mac_clear_status_text (QAction *action)
 
class QToolButton
 
class QWidget
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QAction class provides an abstract user interface action that can be inserted into widgets.

Warning
This function is not part of the public interface. parent and widget are different parent does not define context

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.

Actions can be created as independent objects, but they may also be created during the construction of menus; the QMenu class contains convenience functions for creating actions suitable for use as menu items.

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

Actions are added to widgets using QWidget::addAction() or QGraphicsWidget::addAction(). Note that an action must be added to a widget before it can be used; this is also true when the shortcut should be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext).

Once a QAction has been created it should be added to the relevant menu and toolbar, then connected to the slot which will perform the action. For example:

openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
fileMenu->addAction(openAct);
fileToolBar->addAction(openAct);

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.

See also
QMenu, QToolBar, {Application Example}

Definition at line 64 of file qaction.h.

Enumerations

◆ ActionEvent

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

Enumerator
Trigger 
Hover 

Definition at line 176 of file qaction.h.

◆ MenuRole

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

  • NoRole This action should not be put into the application menu
  • TextHeuristicRole This action should be put in the application menu based on the action's text as described in the QMenuBar documentation.
  • ApplicationSpecificRole This action should be put in the application menu with an application specific role
  • AboutQtRole This action matches handles the "About Qt" menu item.
  • 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 Deploying an Application on Mac OS X).
  • PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu.
  • 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 

Definition at line 94 of file qaction.h.

◆ Priority

This enum defines priorities for actions in user interface.

Since
4.6
  • LowPriority The action should not be prioritized in the user interface.
  • NormalPriority
  • HighPriority The action should be prioritized in the user interface.
See also
priority
Enumerator
LowPriority 
NormalPriority 
HighPriority 

Definition at line 98 of file qaction.h.

◆ SoftKeyRole

This enum describes how an action should be placed in the softkey bar.

Since
4.6

Currently this enum only has an effect on the Symbian platform.

  • NoSoftKey This action should not be used as a softkey
  • PositiveSoftKey This action is used to describe a softkey with a positive or non-destructive role such as Ok, Select, or Options.
  • NegativeSoftKey This action is used to describe a soft ey with a negative or destructive role role such as Cancel, Discard, or Close.
  • SelectSoftKey This action is used to describe a role that selects a particular item or widget in the application.

Actions with a softkey role defined are only visible in the softkey bar when the widget containing the action has focus. If no widget currently has focus, the softkey framework will traverse up the widget parent hierarchy looking for a widget containing softkey actions.

Enumerator
NoSoftKey 
PositiveSoftKey 
NegativeSoftKey 
SelectSoftKey 

Definition at line 96 of file qaction.h.

Constructors and Destructors

◆ QAction() [1/4]

QAction::QAction ( QObject parent)
explicit

Constructs an action with parent.

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

Definition at line 328 of file qaction.cpp.

Referenced by setFont().

329  : QObject(*(new QActionPrivate), parent)
330 {
331  Q_D(QAction);
332  d->group = qobject_cast<QActionGroup *>(parent);
333  if (d->group)
334  d->group->addAction(this);
335 }
double d
Definition: qnumeric_p.h:62
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ QAction() [2/4]

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 (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 351 of file qaction.cpp.

352  : QObject(*(new QActionPrivate), parent)
353 {
354  Q_D(QAction);
355  d->text = text;
356  d->group = qobject_cast<QActionGroup *>(parent);
357  if (d->group)
358  d->group->addAction(this);
359 }
double d
Definition: qnumeric_p.h:62
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
QString text() const
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ QAction() [3/4]

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 (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 373 of file qaction.cpp.

374  : QObject(*(new QActionPrivate), parent)
375 {
376  Q_D(QAction);
377  d->icon = icon;
378  d->text = text;
379  d->group = qobject_cast<QActionGroup *>(parent);
380  if (d->group)
381  d->group->addAction(this);
382 }
double d
Definition: qnumeric_p.h:62
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
QIcon icon() const
QString text() const
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ ~QAction()

QAction::~QAction ( )

Destroys the object and frees allocated resources.

Definition at line 694 of file qaction.cpp.

695 {
696  Q_D(QAction);
697  for (int i = d->widgets.size()-1; i >= 0; --i) {
698  QWidget *w = d->widgets.at(i);
699  w->removeAction(this);
700  }
701 #ifndef QT_NO_GRAPHICSVIEW
702  for (int i = d->graphicsWidgets.size()-1; i >= 0; --i) {
703  QGraphicsWidget *w = d->graphicsWidgets.at(i);
704  w->removeAction(this);
705  }
706 #endif
707  if (d->group)
708  d->group->removeAction(this);
709 #ifndef QT_NO_SHORTCUT
710  if (d->shortcutId && qApp) {
711  qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this);
712  for(int i = 0; i < d->alternateShortcutIds.count(); ++i) {
713  const int id = d->alternateShortcutIds.at(i);
714  qApp->d_func()->shortcutMap.removeShortcut(id, this);
715  }
716  }
717 #endif
718 }
double d
Definition: qnumeric_p.h:62
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ QAction() [4/4]

QAction::QAction ( QActionPrivate dd,
QObject parent 
)
protected
Warning
This function is not part of the public interface.

Definition at line 387 of file qaction.cpp.

388  : QObject(dd, parent)
389 {
390  Q_D(QAction);
391  d->group = qobject_cast<QActionGroup *>(parent);
392  if (d->group)
393  d->group->addAction(this);
394 }
double d
Definition: qnumeric_p.h:62
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

Functions

◆ actionGroup()

QActionGroup * QAction::actionGroup ( ) const

Returns the action group for this action.

If no action group manages this action then 0 will be returned.

See also
QActionGroup, QAction::setActionGroup()

Definition at line 747 of file qaction.cpp.

Referenced by QMenu::initStyleOption(), and QMenuPrivate::QMacMenuPrivate::syncAction().

748 {
749  Q_D(const QAction);
750  return d->group;
751 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ activate()

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 1326 of file qaction.cpp.

Referenced by QMenuBarPrivate::activateAction(), QMenuPrivate::activateCausedStack(), event(), qt_mac_activate_action(), and QMenuBarPrivate::wceEmitSignals().

1327 {
1328  Q_D(QAction);
1329  if(event == Trigger) {
1330  QObject *guard = this;
1331  QMetaObject::addGuard(&guard);
1332  if(d->checkable) {
1333  // the checked action of an exclusive group cannot be unchecked
1334  if (d->checked && (d->group && d->group->isExclusive()
1335  && d->group->checkedAction() == this)) {
1336  if (guard)
1337  emit triggered(true);
1338  QMetaObject::removeGuard(&guard);
1339  return;
1340  }
1341  setChecked(!d->checked);
1342  }
1343  if (guard)
1344  emit triggered(d->checked);
1345 #ifdef QT3_SUPPORT
1346  if (guard)
1347  emit activated(d->param);
1348 #endif
1349  QMetaObject::removeGuard(&guard);
1350  } else if(event == Hover) {
1351  emit hovered();
1352  }
1353 }
double d
Definition: qnumeric_p.h:62
bool event(QEvent *)
Reimplemented Function
Definition: qaction.cpp:1256
static void addGuard(QObject **ptr)
Definition: qobject.cpp:390
void hovered()
This signal is emitted when an action is highlighted by the user; for example, when the user pauses w...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
void setChecked(bool)
Definition: qaction.cpp:1138
static void removeGuard(QObject **ptr)
Definition: qobject.cpp:406
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ associatedGraphicsWidgets()

QList< QGraphicsWidget * > QAction::associatedGraphicsWidgets ( ) const

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

Since
4.5
See also
QWidget::addAction(), associatedWidgets()

Definition at line 432 of file qaction.cpp.

433 {
434  Q_D(const QAction);
435  return d->graphicsWidgets;
436 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ associatedWidgets()

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

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

Since
4.2
See also
QWidget::addAction(), associatedGraphicsWidgets()

Definition at line 416 of file qaction.cpp.

Referenced by QDialogButtonBox::event(), and waitForPopup().

417 {
418  Q_D(const QAction);
419  return d->widgets;
420 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ autoRepeat()

bool QAction::autoRepeat ( ) const

Referenced by setAutoRepeat().

◆ changed

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.

See also
QWidget::actionEvent()

◆ data()

QVariant QAction::data ( ) const

Returns the user data as set in QAction::setData.

See also
setData()

Definition at line 1280 of file qaction.cpp.

Referenced by QCalendarWidgetPrivate::_q_monthChanged(), QmlJSDebugger::QmlToolBar::changeAnimationSpeed(), QMultiInputContext::changeSlave(), QmlJSDebugger::LiveSelectionTool::contextMenuElementHovered(), QmlJSDebugger::LiveSelectionTool::contextMenuElementSelected(), QmlJSDebugger::QmlToolBar::setAnimationSpeed(), and setData().

1281 {
1282  Q_D(const QAction);
1283  return d->userData;
1284 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ event()

bool QAction::event ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Reimplemented in QWidgetAction.

Definition at line 1256 of file qaction.cpp.

Referenced by QWidgetAction::event().

1257 {
1258 #ifndef QT_NO_SHORTCUT
1259  if (e->type() == QEvent::Shortcut) {
1260  QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
1261  Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()),
1262  "QAction::event",
1263  "Received shortcut event from incorrect shortcut");
1264  if (se->isAmbiguous())
1265  qWarning("QAction::eventFilter: Ambiguous shortcut overload: %s", QString(se->key()).toLatin1().constData());
1266  else
1267  activate(Trigger);
1268  return true;
1269  }
1270 #endif
1271  return QObject::event(e);
1272 }
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
Definition: qaction.cpp:1326
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
Definition: qevent.h:675
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
Q_CORE_EXPORT void qWarning(const char *,...)
const QKeySequence & key()
Definition: qevent.h:681
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
bool isAmbiguous()
Definition: qevent.h:685
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ font()

QFont QAction::font ( ) const

Referenced by setFont().

◆ hover

void QAction::hover ( )
inlineslot

This is a convenience slot that calls activate(Hover).

Definition at line 219 of file qaction.h.

219 { activate(Hover); }
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
Definition: qaction.cpp:1326

◆ hovered

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

See also
QAction::activate()

Referenced by activate().

◆ icon()

QIcon QAction::icon ( ) const

Referenced by QAction(), setFont(), and setIcon().

◆ iconText()

QString QAction::iconText ( ) const

Referenced by setIconText().

◆ isCheckable()

bool QAction::isCheckable ( ) const

Definition at line 1105 of file qaction.cpp.

Referenced by QMenu::initStyleOption(), qt_wce_insert_action(), QToolButton::setDefaultAction(), and QMenuPrivate::updateActionRects().

1106 {
1107  Q_D(const QAction);
1108  return d->checkable;
1109 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ isChecked()

bool QAction::isChecked ( ) const

◆ isEnabled()

bool QAction::isEnabled ( ) const

◆ isIconVisibleInMenu()

bool QAction::isIconVisibleInMenu ( ) const

Definition at line 1651 of file qaction.cpp.

Referenced by QMenu::initStyleOption(), and QMenuPrivate::QMacMenuPrivate::syncAction().

1652 {
1653  Q_D(const QAction);
1654  if (d->iconVisibleInMenu == -1) {
1656  }
1657  return d->iconVisibleInMenu;
1658 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ isSeparator()

bool QAction::isSeparator ( ) const

◆ isVisible()

bool QAction::isVisible ( ) const

Definition at line 1246 of file qaction.cpp.

Referenced by actualMenuItemVisibility(), QSoftKeyManager::appendSoftkeys(), QMenuBarPrivate::calcActionRects(), QMenuPrivate::getLastVisibleAction(), QToolBarItem::isEmpty(), QMenu::isEmpty(), QMenuBarPrivate::macUpdateMenuBarImmediatly(), qt_mac_menu_event(), qt_wce_insert_action(), QAccessibleMenuItem::state(), QMenuPrivate::QMacMenuPrivate::syncAction(), and QMenuPrivate::updateActionRects().

1247 {
1248  Q_D(const QAction);
1249  return d->visible;
1250 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ menu()

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.

See also
QMenu::addAction()

Definition at line 793 of file qaction.cpp.

Referenced by QMenuBarPrivate::_q_internalShortcutActivated(), QAccessibleMenu::actionText(), QAccessibleMenuBar::actionText(), QAccessibleMenuItem::actionText(), actualMenuItemVisibility(), QAccessibleMenuItem::childCount(), QAxServerBase::createMenu(), QAxServerBase::createPopup(), QAccessibleMenu::doAction(), QAccessibleMenuBar::doAction(), QAccessibleMenuItem::doAction(), QToolButtonPrivate::hasMenu(), QAccessibleMenuItem::indexOfChild(), QMenuPrivate::init(), QMenu::initStyleOption(), QMenu::keyPressEvent(), QMenuBar::mouseReleaseEvent(), QMenu::mouseReleaseEvent(), QAxClientSite::OnPosRectChange(), QMenuBarPrivate::popupAction(), QMenuPrivate::popupAction(), QToolButtonPrivate::popupTimerDone(), qt_mac_menu_merge_action(), qt_wce_get_quit_action(), qt_wce_insert_action(), QMenuBarPrivate::QWceMenuBarPrivate::rebuild(), QAccessibleMenuItem::rect(), QDecoration::region(), QMenuPrivate::setCurrentAction(), QToolButton::setDefaultAction(), setMenu(), QMenuBar::setNativeMenuBar(), QMenu::setSeparatorsCollapsible(), QMenuPrivate::setSyncAction(), QAccessibleMenuItem::state(), QMenuBarPrivate::QMacMenuBarPrivate::syncAction(), QMenuPrivate::QMacMenuPrivate::syncAction(), QAccessibleMenuItem::text(), QMenuPrivate::wceCommands(), and QMenuBarPrivate::wceEmitSignals().

794 {
795  Q_D(const QAction);
796  return d->menu;
797 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ menuRole()

MenuRole QAction::menuRole ( ) const

Referenced by setMenuRole().

◆ parentWidget()

QWidget * QAction::parentWidget ( ) const

Returns the parent widget.

Definition at line 399 of file qaction.cpp.

Referenced by QSoftKeyManager::sendKeyEvent().

400 {
401  QObject *ret = parent();
402  while (ret && !ret->isWidgetType())
403  ret = ret->parent();
404  return (QWidget*)ret;
405 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ priority()

Priority QAction::priority ( ) const

Referenced by setPriority().

◆ setActionGroup()

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.

See also
QActionGroup, QAction::actionGroup()

Definition at line 728 of file qaction.cpp.

729 {
730  Q_D(QAction);
731  if(group == d->group)
732  return;
733 
734  if(d->group)
735  d->group->removeAction(this);
736  d->group = group;
737  if(group)
738  group->addAction(this);
739 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QAction * addAction(QAction *a)
Adds the action to this group, and returns it.
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setAutoRepeat()

void QAction::setAutoRepeat ( bool  on)

Definition at line 589 of file qaction.cpp.

590 {
591  Q_D(QAction);
592  if (d->autorepeat == on)
593  return;
594  QAPP_CHECK("setAutoRepeat");
595  d->autorepeat = on;
596  d->redoGrab(qApp->d_func()->shortcutMap);
597  d->redoGrabAlternate(qApp->d_func()->shortcutMap);
598  d->sendDataChanged();
599 }
double d
Definition: qnumeric_p.h:62
#define QAPP_CHECK(functionName)
Definition: qaction.cpp:55
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setCheckable()

void QAction::setCheckable ( bool  b)

Definition at line 1094 of file qaction.cpp.

Referenced by QFileDialogPrivate::createMenuActions(), QMdiSubWindowPrivate::createSystemMenu(), QFileDialogPrivate::createWidgets(), QmlJSDebugger::QmlToolBar::QmlToolBar(), QMultiInputContext::QMultiInputContext(), QWhatsThis::QWhatsThis(), and QWhatsThisAction::QWhatsThisAction().

1095 {
1096  Q_D(QAction);
1097  if (d->checkable == b)
1098  return;
1099 
1100  d->checkable = b;
1101  d->checked = false;
1102  d->sendDataChanged();
1103 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setChecked

void QAction::setChecked ( bool  b)
slot

Definition at line 1138 of file qaction.cpp.

Referenced by QActionGroupPrivate::_q_actionChanged(), activate(), QmlJSDebugger::QmlToolBar::activateColorPickerOnClick(), QmlJSDebugger::QmlToolBar::activateMarqueeSelectToolOnClick(), QmlJSDebugger::QmlToolBar::activateSelectToolOnClick(), QmlJSDebugger::QmlToolBar::activateZoomOnClick(), QFileDialogPrivate::createWidgets(), QWorkspacePrivate::init(), QmlJSDebugger::QmlToolBar::QmlToolBar(), QMultiInputContext::QMultiInputContext(), QFileDialog::restoreState(), QmlJSDebugger::QmlToolBar::setAnimationSpeed(), QmlJSDebugger::QmlToolBar::setDesignModeBehavior(), QPrintPreviewDialogPrivate::setFitting(), toggle(), and QWhatsThisPrivate::~QWhatsThisPrivate().

1139 {
1140  Q_D(QAction);
1141  if (!d->checkable || d->checked == b)
1142  return;
1143 
1144  QPointer<QAction> guard(this);
1145  d->checked = b;
1146  d->sendDataChanged();
1147  if (guard)
1148  emit toggled(b);
1149 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void toggled(bool)
This signal is emitted whenever a checkable action changes its isChecked() status.
#define emit
Definition: qobjectdefs.h:76
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setData()

void QAction::setData ( const QVariant userData)

Sets the action's internal data to the given userData.

See also
data()

Definition at line 1297 of file qaction.cpp.

Referenced by QmlJSDebugger::LiveSelectionTool::createContextMenu(), QCalendarWidgetPrivate::createNavigationBar(), QmlJSDebugger::QmlToolBar::QmlToolBar(), and QMultiInputContext::QMultiInputContext().

1298 {
1299  Q_D(QAction);
1300  d->userData = data;
1301  d->sendDataChanged();
1302 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QVariant data() const
Returns the user data as set in QAction::setData.
Definition: qaction.cpp:1280
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setDisabled

void QAction::setDisabled ( bool  b)
inlineslot

This is a convenience function for the enabled property, that is useful for signals–slots connections.

If b is true the action is disabled; otherwise it is enabled.

Definition at line 223 of file qaction.h.

Referenced by QDecoration::buildSysMenu().

223 { setEnabled(!b); }
void setEnabled(bool)
Definition: qaction.cpp:1192

◆ setEnabled

void QAction::setEnabled ( bool  b)
slot

Definition at line 1192 of file qaction.cpp.

Referenced by QScriptDebuggerPrivate::_q_onFindCodeRequest(), QFileDialogPrivate::_q_showContextMenu(), QActionGroup::addAction(), QDecoration::buildSysMenu(), QAbstractSpinBox::contextMenuEvent(), QFileDialogPrivate::createMenuActions(), QUndoGroup::createRedoAction(), QUndoStack::createRedoAction(), QTextControl::createStandardContextMenu(), QLineEdit::createStandardContextMenu(), QMdiSubWindowPrivate::createSystemMenu(), QUndoGroup::createUndoAction(), QUndoStack::createUndoAction(), QScriptDebuggerPrivate::handleResponse(), QmlJSDebugger::QmlToolBar::setDesignModeBehaviorOnClick(), QMdiSubWindowPrivate::setEnabled(), QSidebar::showContextMenu(), QScriptDebuggerPrivate::startInteraction(), and QMenuPrivate::QMacMenuPrivate::syncAction().

1193 {
1194  Q_D(QAction);
1195  if (b == d->enabled && b != d->forceDisabled)
1196  return;
1197  d->forceDisabled = !b;
1198  if (b && (!d->visible || (d->group && !d->group->isEnabled())))
1199  return;
1200  QAPP_CHECK("setEnabled");
1201  d->enabled = b;
1202 #ifndef QT_NO_SHORTCUT
1203  d->setShortcutEnabled(b, qApp->d_func()->shortcutMap);
1204 #endif
1205  d->sendDataChanged();
1206 }
double d
Definition: qnumeric_p.h:62
#define QAPP_CHECK(functionName)
Definition: qaction.cpp:55
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setFont()

void QAction::setFont ( const QFont font)

Definition at line 623 of file qaction.cpp.

Referenced by QmlJSDebugger::LiveSelectionTool::createContextMenu().

624 {
625  Q_D(QAction);
626  if (d->font == font)
627  return;
628 
629  d->fontSet = true;
630  d->font = font;
631  d->sendDataChanged();
632 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QFont font() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setIcon()

void QAction::setIcon ( const QIcon icon)

Definition at line 772 of file qaction.cpp.

Referenced by QMdiSubWindowPrivate::createSystemMenu(), QMenuBar::defaultAction(), menuItemEntry(), qt_setupActionIcon(), QWhatsThis::QWhatsThis(), QWhatsThisAction::QWhatsThisAction(), QMenu::setSeparatorsCollapsible(), and QmlJSDebugger::QmlToolBar::updatePlayAction().

773 {
774  Q_D(QAction);
775  d->icon = icon;
776  d->sendDataChanged();
777 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QIcon icon() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setIconText()

void QAction::setIconText ( const QString text)

Definition at line 907 of file qaction.cpp.

908 {
909  Q_D(QAction);
910  if (d->iconText == text)
911  return;
912 
913  d->iconText = text;
914  d->sendDataChanged();
915 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QString text() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setIconVisibleInMenu()

void QAction::setIconVisibleInMenu ( bool  visible)

Definition at line 1636 of file qaction.cpp.

1637 {
1638  Q_D(QAction);
1639  if (d->iconVisibleInMenu == -1 || visible != bool(d->iconVisibleInMenu)) {
1640  int oldValue = d->iconVisibleInMenu;
1641  d->iconVisibleInMenu = visible;
1642  // Only send data changed if we really need to.
1643  if (oldValue != -1
1644  || (oldValue == -1
1645  && visible == !QApplication::instance()->testAttribute(Qt::AA_DontShowIconsInMenus))) {
1646  d->sendDataChanged();
1647  }
1648  }
1649 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool visible
whether the action can be seen (e.g.
Definition: qaction.h:87
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setMenu()

void QAction::setMenu ( QMenu menu)

Sets the menu contained by this action to the specified menu.

Definition at line 802 of file qaction.cpp.

Referenced by QmlJSDebugger::QmlToolBar::QmlToolBar().

803 {
804  Q_D(QAction);
805  if (d->menu)
806  d->menu->d_func()->setOverrideMenuAction(0); //we reset the default action of any previous menu
807  d->menu = menu;
808  if (menu)
809  menu->d_func()->setOverrideMenuAction(this);
810  d->sendDataChanged();
811 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setMenuRole()

void QAction::setMenuRole ( MenuRole  menuRole)

Definition at line 1569 of file qaction.cpp.

1570 {
1571  Q_D(QAction);
1572  if (d->menuRole == menuRole)
1573  return;
1574 
1575  d->menuRole = menuRole;
1576  d->sendDataChanged();
1577 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
MenuRole menuRole() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setPriority()

void QAction::setPriority ( Priority  priority)

Definition at line 1056 of file qaction.cpp.

1057 {
1058  Q_D(QAction);
1059  if (d->priority == priority)
1060  return;
1061 
1062  d->priority = priority;
1063  d->sendDataChanged();
1064 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Priority priority() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setSeparator()

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.

See also
QAction::isSeparator()

Definition at line 823 of file qaction.cpp.

Referenced by QMenuBar::addSeparator(), QMenu::addSeparator(), QToolBar::addSeparator(), QMenuBar::defaultAction(), QMenuBar::insertSeparator(), QMenu::insertSeparator(), QToolBar::insertSeparator(), QMultiInputContext::QMultiInputContext(), and QMenu::setSeparatorsCollapsible().

824 {
825  Q_D(QAction);
826  if (d->separator == b)
827  return;
828 
829  d->separator = b;
830  d->sendDataChanged();
831 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setShortcut()

void QAction::setShortcut ( const QKeySequence shortcut)

Definition at line 450 of file qaction.cpp.

Referenced by QMenu::addAction(), QmlJSDebugger::LiveSelectionTool::createContextMenu(), QFileDialogPrivate::createMenuActions(), QMenuBar::defaultAction(), menuItemEntry(), QWhatsThisAction::QWhatsThisAction(), setFont(), QMenu::setSeparatorsCollapsible(), and QmlJSDebugger::ZoomTool::ZoomTool().

451 {
452  QAPP_CHECK("setShortcut");
453 
454  Q_D(QAction);
455  if (d->shortcut == shortcut)
456  return;
457 
458  d->shortcut = shortcut;
459  d->redoGrab(qApp->d_func()->shortcutMap);
460  d->sendDataChanged();
461 }
double d
Definition: qnumeric_p.h:62
#define QAPP_CHECK(functionName)
Definition: qaction.cpp:55
#define Q_D(Class)
Definition: qglobal.h:2482
QKeySequence shortcut() const
#define qApp
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setShortcutContext()

void QAction::setShortcutContext ( Qt::ShortcutContext  context)

Definition at line 558 of file qaction.cpp.

559 {
560  Q_D(QAction);
561  if (d->shortcutContext == context)
562  return;
563  QAPP_CHECK("setShortcutContext");
564  d->shortcutContext = context;
565  d->redoGrab(qApp->d_func()->shortcutMap);
566  d->redoGrabAlternate(qApp->d_func()->shortcutMap);
567  d->sendDataChanged();
568 }
double d
Definition: qnumeric_p.h:62
#define QAPP_CHECK(functionName)
Definition: qaction.cpp:55
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setShortcuts() [1/2]

void QAction::setShortcuts ( const QList< QKeySequence > &  shortcuts)

Sets shortcuts as the list of shortcuts that trigger the action.

Since
4.2

The first element of the list is the primary shortcut.

See also
shortcut

Definition at line 474 of file qaction.cpp.

Referenced by QMdiSubWindowPrivate::createSystemMenu(), and setShortcuts().

475 {
476  Q_D(QAction);
477 
478  QList <QKeySequence> listCopy = shortcuts;
479 
480  QKeySequence primary;
481  if (!listCopy.isEmpty())
482  primary = listCopy.takeFirst();
483 
484  if (d->shortcut == primary && d->alternateShortcuts == listCopy)
485  return;
486 
487  QAPP_CHECK("setShortcuts");
488 
489  d->shortcut = primary;
490  d->alternateShortcuts = listCopy;
491  d->redoGrab(qApp->d_func()->shortcutMap);
492  d->redoGrabAlternate(qApp->d_func()->shortcutMap);
493  d->sendDataChanged();
494 }
double d
Definition: qnumeric_p.h:62
#define QAPP_CHECK(functionName)
Definition: qaction.cpp:55
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
#define qApp
QList< QKeySequence > shortcuts() const
Returns the list of shortcuts, with the primary shortcut as the first element of the list...
Definition: qaction.cpp:537
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setShortcuts() [2/2]

void QAction::setShortcuts ( QKeySequence::StandardKey  key)

Sets a platform dependent list of shortcuts based on the key.

Since
4.2

The result of calling this function will depend on the currently running platform. Note that more than one shortcut can assigned by this action. If only the primary shortcut is required, use setShortcut instead.

See also
QKeySequence::keyBindings()

Definition at line 509 of file qaction.cpp.

510 {
512  setShortcuts(list);
513 }
static QList< QKeySequence > keyBindings(StandardKey key)
Returns a list of key bindings for the given key.
void setShortcuts(const QList< QKeySequence > &shortcuts)
Sets shortcuts as the list of shortcuts that trigger the action.
Definition: qaction.cpp:474
int key

◆ setSoftKeyRole()

void QAction::setSoftKeyRole ( SoftKeyRole  softKeyRole)

Definition at line 1599 of file qaction.cpp.

Referenced by QDialogButtonBoxPrivate::addButton(), QSoftKeyManager::createAction(), and QWizardPrivate::ensureButton().

1600 {
1601  Q_D(QAction);
1602  if (d->softKeyRole == softKeyRole)
1603  return;
1604 
1605  d->softKeyRole = softKeyRole;
1606  d->sendDataChanged();
1607 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
SoftKeyRole softKeyRole() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setStatusTip()

void QAction::setStatusTip ( const QString statusTip)

Definition at line 974 of file qaction.cpp.

975 {
976  Q_D(QAction);
977  if (d->statustip == statustip)
978  return;
979 
980  d->statustip = statustip;
981  d->sendDataChanged();
982 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setText()

void QAction::setText ( const QString text)

Definition at line 860 of file qaction.cpp.

Referenced by QMenuBar::defaultAction(), QFileDialogPrivate::retranslateStrings(), QDialogButtonBoxPrivate::retranslateStrings(), QUndoAction::setPrefixedText(), and QMenu::setSeparatorsCollapsible().

861 {
862  Q_D(QAction);
863  if (d->text == text)
864  return;
865 
866  d->text = text;
867  d->sendDataChanged();
868 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QString text() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setToolTip()

void QAction::setToolTip ( const QString tip)

Definition at line 939 of file qaction.cpp.

940 {
941  Q_D(QAction);
942  if (d->tooltip == tooltip)
943  return;
944 
945  d->tooltip = tooltip;
946  d->sendDataChanged();
947 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setVisible

void QAction::setVisible ( bool  b)
slot

Definition at line 1230 of file qaction.cpp.

Referenced by QActionGroup::addAction(), QSoftKeyManager::createAction(), QAxClientSite::qt_metacall(), QWidgetAction::setDefaultWidget(), and QMdiSubWindowPrivate::setVisible().

1231 {
1232  Q_D(QAction);
1233  if (b == d->visible && b != d->forceInvisible)
1234  return;
1235  QAPP_CHECK("setVisible");
1236  d->forceInvisible = !b;
1237  d->visible = b;
1238  d->enabled = b && !d->forceDisabled && (!d->group || d->group->isEnabled()) ;
1239 #ifndef QT_NO_SHORTCUT
1240  d->setShortcutEnabled(d->enabled, qApp->d_func()->shortcutMap);
1241 #endif
1242  d->sendDataChanged();
1243 }
double d
Definition: qnumeric_p.h:62
#define QAPP_CHECK(functionName)
Definition: qaction.cpp:55
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ setWhatsThis()

void QAction::setWhatsThis ( const QString what)

Definition at line 1003 of file qaction.cpp.

1004 {
1005  Q_D(QAction);
1006  if (d->whatsthis == whatsthis)
1007  return;
1008 
1009  d->whatsthis = whatsthis;
1010  d->sendDataChanged();
1011 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ shortcut()

QKeySequence QAction::shortcut ( ) const

Referenced by setFont(), setShortcut(), and setShortcuts().

◆ shortcutContext()

Qt::ShortcutContext QAction::shortcutContext ( ) const

Referenced by setShortcutContext().

◆ shortcuts()

QList< QKeySequence > QAction::shortcuts ( ) const

Returns the list of shortcuts, with the primary shortcut as the first element of the list.

Since
4.2
See also
setShortcuts()

Definition at line 537 of file qaction.cpp.

Referenced by setShortcuts().

538 {
539  Q_D(const QAction);
541  if (!d->shortcut.isEmpty())
542  shortcuts << d->shortcut;
543  if (!d->alternateShortcuts.isEmpty())
544  shortcuts << d->alternateShortcuts;
545  return shortcuts;
546 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QList< QKeySequence > shortcuts() const
Returns the list of shortcuts, with the primary shortcut as the first element of the list...
Definition: qaction.cpp:537
if(void) toggleToolbarShown
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ showStatusText()

bool QAction::showStatusText ( QWidget widget = 0)

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.

See also
statusTip

Definition at line 1315 of file qaction.cpp.

Referenced by QMenuBarPrivate::activateAction(), QMenuPrivate::activateAction(), qt_mac_activate_action(), and QMenuPrivate::setCurrentAction().

1316 {
1317  return d_func()->showStatusText(widget, statusTip());
1318 }
QString statusTip() const

◆ softKeyRole()

SoftKeyRole QAction::softKeyRole ( ) const

Referenced by setSoftKeyRole().

◆ statusTip()

QString QAction::statusTip ( ) const

Referenced by setStatusTip(), and showStatusText().

◆ text()

QString QAction::text ( ) const

Referenced by QAction(), setFont(), setIconText(), and setText().

◆ toggle

void QAction::toggle ( )
slot

This is a convenience function for the checked property.

Connect to it to change the checked state to its opposite state.

Definition at line 1120 of file qaction.cpp.

1121 {
1122  Q_D(QAction);
1123  setChecked(!d->checked);
1124 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void setChecked(bool)
Definition: qaction.cpp:1138
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ toggled

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

checked is true if the action is checked, or false if the action is unchecked.

See also
QAction::activate(), QAction::triggered(), checked

Referenced by QWhatsThis::QWhatsThis(), and setChecked().

◆ toolTip()

QString QAction::toolTip ( ) const

Referenced by setToolTip().

◆ trigger

void QAction::trigger ( )
inlineslot

This is a convenience slot that calls activate(Trigger).

Definition at line 218 of file qaction.h.

Referenced by QAccessibleMenuItem::doAction().

218 { activate(Trigger); }
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
Definition: qaction.cpp:1326

◆ triggered

void QAction::triggered ( bool  checked = false)
signal

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.

See also
QAction::activate(), QAction::toggled(), checked

Referenced by activate(), and QWhatsThisAction::QWhatsThisAction().

◆ whatsThis()

QString QAction::whatsThis ( ) const

Referenced by setWhatsThis().

Friends and Related Functions

◆ QActionGroup

friend class QActionGroup
friend

Definition at line 243 of file qaction.h.

◆ QGraphicsWidget

friend class QGraphicsWidget
friend

Definition at line 241 of file qaction.h.

◆ QMenu

friend class QMenu
friend

Definition at line 244 of file qaction.h.

◆ QMenuBar

friend class QMenuBar
friend

Definition at line 246 of file qaction.h.

◆ QMenuPrivate

friend class QMenuPrivate
friend

Definition at line 245 of file qaction.h.

◆ QShortcutMap

friend class QShortcutMap
friend

Definition at line 247 of file qaction.h.

◆ qt_mac_clear_status_text

void qt_mac_clear_status_text ( QAction action)
friend

◆ QToolButton

friend class QToolButton
friend

Definition at line 248 of file qaction.h.

Referenced by QWhatsThis::QWhatsThis().

◆ QWidget

friend class QWidget
friend

Definition at line 242 of file qaction.h.

Properties

◆ autoRepeat

bool QAction::autoRepeat
private

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.

Definition at line 85 of file qaction.h.

Referenced by QToolButtonPrivate::popupTimerDone().

◆ checkable

QAction::checkable
private

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.

See also
QAction::setChecked()

Definition at line 72 of file qaction.h.

◆ checked

QAction::checked
private

whether the action is checked.

Only checkable actions can be checked. By default, this is false (the action is unchecked).

See also
checkable

Definition at line 73 of file qaction.h.

◆ enabled

QAction::enabled
private

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.

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

See also
text

Definition at line 74 of file qaction.h.

◆ font

QFont QAction::font
private

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.

See also
QAction::setText() QStyle

Definition at line 81 of file qaction.h.

Referenced by QmlJSDebugger::LiveSelectionTool::createContextMenu(), QMenu::initStyleOption(), QToolButton::setDefaultAction(), and QMenuPrivate::QMacMenuPrivate::syncAction().

◆ icon

QIcon QAction::icon
private

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.

On Symbian the icons which are passed to softkeys, i.e. to actions with softkey role, need to have pixmap alpha channel correctly set otherwise drawing artifacts will appear when softkey is pressed down.

If a null icon (QIcon::isNull() is passed into this function, the icon of the action is cleared.

Definition at line 75 of file qaction.h.

Referenced by QMenuBarPrivate::calcActionRects(), QMenuBar::initStyleOption(), QMenu::initStyleOption(), QToolButton::setDefaultAction(), QMenuPrivate::QMacMenuPrivate::syncAction(), and QMenuPrivate::updateActionRects().

◆ iconText

QString QAction::iconText
private

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.

See also
setToolTip(), setStatusTip()

Definition at line 77 of file qaction.h.

Referenced by qt_wce_insert_action(), QToolButton::setDefaultAction(), and QNSOpenSavePanelDelegate::strip:.

◆ iconVisibleInMenu

QAction::iconVisibleInMenu
private

Whether or not an action should show an icon in a menu.

Since
4.4

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 abscence) of the attribute.

For example:

QApplication app(argc, argv);
app.setAttribute(Qt::AA_DontShowIconsInMenus); // Icons are *no longer shown* in menus
// ...
QAction *myAction = new QAction();
// ...
myAction->setIcon(SomeIcon);
myAction->setIconVisibleInMenu(true); // Icon *will* be shown in menus for *this* action.
See also
QAction::icon QApplication::setAttribute()

Definition at line 90 of file qaction.h.

◆ menuRole

QAction::MenuRole QAction::menuRole
private

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

Definition at line 88 of file qaction.h.

Referenced by qt_mac_menu_merge_accel(), qt_mac_menu_merge_action(), qt_mac_menu_merge_text(), qt_wce_get_quit_action(), QMenuPrivate::QMacMenuPrivate::syncAction(), and QMacMenuAction::~QMacMenuAction().

◆ priority

QAction::Priority QAction::priority
private

the actions's priority in the user interface.

Since
4.6

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.

Definition at line 91 of file qaction.h.

◆ shortcut

QKeySequence QAction::shortcut
private

the action's primary shortcut key

Returns the primary shortcut.

Valid keycodes for this property can be found in Qt::Key and Qt::Modifier . There is no default shortcut key.

See also
setShortcuts()

Definition at line 83 of file qaction.h.

Referenced by QAccessibleWidget::actionText(), QMenu::initStyleOption(), QAccessibleMenuItem::keyBindings(), qt_mac_menu_event(), qt_mac_menu_merge_accel(), QMenuPrivate::QMacMenuPrivate::syncAction(), QAccessibleMenu::text(), QAccessibleMenuItem::text(), and QMenuPrivate::updateActionRects().

◆ shortcutContext

Qt::ShortcutContext QAction::shortcutContext
private

the context for the action's shortcut

Valid values for this property can be found in Qt::ShortcutContext . The default value is Qt::WindowShortcut.

Definition at line 84 of file qaction.h.

◆ softKeyRole

QAction::SoftKeyRole QAction::softKeyRole
private

the action's softkey role

Since
4.6

This indicates what type of role this action describes in the softkey framework on platforms where such a framework is supported. Currently this is only supported on the Symbian platform.

The softkey role can be changed any time.

Definition at line 89 of file qaction.h.

Referenced by QSoftKeyManager::appendSoftkeys().

◆ statusTip

QString QAction::statusTip
private

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.

See also
setToolTip() showStatusText()

Definition at line 79 of file qaction.h.

Referenced by QToolButton::setDefaultAction().

◆ text

QString QAction::text
private

◆ toolTip

QString QAction::toolTip
private

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.

See also
setStatusTip() setShortcut()

Definition at line 78 of file qaction.h.

Referenced by QAccessibleWidget::actionText(), and QToolButton::setDefaultAction().

◆ visible

QAction::visible
private

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

Definition at line 87 of file qaction.h.

Referenced by setIconVisibleInMenu().

◆ whatsThis

QString QAction::whatsThis
private

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.

See also
QWhatsThis Q3StyleSheet

Definition at line 80 of file qaction.h.

Referenced by QMenuPrivate::activateAction(), QToolButton::setDefaultAction(), and QAccessibleMenu::text().


The documentation for this class was generated from the following files: