Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QAction Class Reference

The QAction class provides an abstraction for user commands that can be added to different user interface components. More...

#include <qaction.h>

+ Inheritance diagram for QAction:
+ Collaboration diagram for QAction:

Public Types

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

Public Slots

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

Signals

void changed ()
 This signal is emitted when an action has changed.
 
void enabledChanged (bool enabled)
 
void checkableChanged (bool checkable)
 
void visibleChanged ()
 
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.
 
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.
 
void toggled (bool)
 This signal is emitted whenever a checkable action changes its isChecked() status.
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QAction (QObject *parent=nullptr)
 Constructs an action with parent.
 
 QAction (const QString &text, QObject *parent=nullptr)
 Constructs an action with some text and parent.
 
 QAction (const QIcon &icon, const QString &text, QObject *parent=nullptr)
 Constructs an action with an icon and some text and parent.
 
 ~QAction ()
 Destroys the object and frees allocated resources.
 
QList< QObject * > associatedObjects () const
 
void setActionGroup (QActionGroup *group)
 Sets this action group to group.
 
QActionGroupactionGroup () const
 Returns the action group for this action.
 
void setIcon (const QIcon &icon)
 
QIcon icon () const
 
void setText (const QString &text)
 
QString text () const
 
void setIconText (const QString &text)
 
QString iconText () const
 
void setToolTip (const QString &tip)
 
QString toolTip () const
 
void setStatusTip (const QString &statusTip)
 
QString statusTip () const
 
void setWhatsThis (const QString &what)
 
QString whatsThis () const
 
void setPriority (Priority priority)
 
Priority priority () const
 
void setSeparator (bool b)
 If b is true then this action will be considered a separator.
 
bool isSeparator () const
 Returns true if this action is a separator action; otherwise it returns false.
 
void setFont (const QFont &font)
 
QFont font () const
 
void setCheckable (bool)
 
bool isCheckable () const
 
QVariant data () const
 Returns the user data as set in QAction::setData.
 
void setData (const QVariant &var)
 Sets the action's internal data to the given data.
 
bool isChecked () const
 
bool isEnabled () const
 
bool isVisible () const
 
void activate (ActionEvent event)
 Sends the relevant signals for ActionEvent event.
 
void setMenuRole (MenuRole menuRole)
 
MenuRole menuRole () const
 
template<typename T = QMenu*>
menu () const
 Returns the menu contained by this action.
 
template<typename T = QMenu*>
void setMenu (T m)
 Sets the menu contained by this action to the specified menu.
 
void setIconVisibleInMenu (bool visible)
 
bool isIconVisibleInMenu () const
 
void setShortcutVisibleInContextMenu (bool show)
 
bool isShortcutVisibleInContextMenu () const
 
bool showStatusText (QObject *object=nullptr)
 Updates the relevant status bar for the UI represented by object by sending a QStatusTipEvent.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) 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.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
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.
 

Protected Member Functions

bool event (QEvent *) override
 \reimp
 
 QAction (QActionPrivate &dd, QObject *parent)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Properties

bool checkable
 whether the action is a checkable action
 
bool checked
 whether the action is checked.
 
bool enabled
 whether the action is enabled
 
QIcon icon
 the action's icon
 
QString text
 the action's descriptive text
 
QString iconText
 the action's descriptive icon text
 
QString toolTip
 the action's tooltip
 
QString statusTip
 the action's status tip
 
QString whatsThis
 the action's "What's This?" help text
 
QFont font
 the action's font
 
bool visible
 whether the action can be seen (e.g.
 
MenuRole menuRole
 the action's menu role
 
bool iconVisibleInMenu
 Whether or not an action should show an icon in a menu.
 
bool shortcutVisibleInContextMenu
 Whether or not an action should show a shortcut in a context menu.
 
Priority priority
 the actions's priority in the user interface.
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Friends

class QActionGroup
 
class QWidget
 
class QMenu
 
class QMenuPrivate
 
class QToolButton
 
class QGraphicsWidget
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

The QAction class provides an abstraction for user commands that can be added to different user interface components.

Since
6.0

\inmodule QtGui

In applications many common commands can be invoked via menus, toolbar buttons, and keyboard shortcuts. Since the user expects each command to be performed in the same way, regardless of the user interface used, it is useful to represent each command as an action.

Actions can be added to user interface elements such as menus and toolbars, and will automatically keep the UI in sync. For example, in a word processor, if the user presses a Bold toolbar button, the Bold menu item will automatically be checked.

A QAction may contain an icon, descriptive text, icon text, a keyboard shortcut, status text, "What's This?" text, and a tooltip. All properties can be set independently with setIcon(), setText(), setIconText(), setShortcut(), setStatusTip(), setWhatsThis(), and setToolTip(). Icon and text, as the two most important properties, can also be set in the constructor. It's possible to set an individual font with setFont(), which e.g. menus respect when displaying the action as a menu item.

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.

Definition at line 29 of file qaction.h.

Member Enumeration Documentation

◆ ActionEvent

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

\value Trigger this will cause the QAction::triggered() signal to be emitted.

\value Hover this will cause the QAction::hovered() signal to be emitted.

Enumerator
Trigger 
Hover 

Definition at line 175 of file qaction.h.

◆ MenuRole

This enum describes how an action should be moved into the application menu on \macos.

\value NoRole This action should not be put into the application menu \value TextHeuristicRole This action should be put in the application menu based on the action's text as described in the QMenuBar documentation. \value ApplicationSpecificRole This action should be put in the application menu with an application specific role \value AboutQtRole This action handles the "About Qt" menu item. \value AboutRole This action should be placed where the "About" menu item is in the application menu. The text of the menu item will be set to "About <application name>". The application name is fetched from the {Info.plist} file in the application's bundle (See \l{Qt for macOS - Deployment}). \value PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu. \value QuitRole This action should be placed where the Quit menu item is in the application menu.

Setting this value only has effect on items that are in the immediate menus of the menubar, not the submenus of those menus. For example, if you have File menu in your menubar and the File menu has a submenu, setting the MenuRole for the actions in that submenu have no effect. They will never be moved.

Enumerator
NoRole 
TextHeuristicRole 
ApplicationSpecificRole 
AboutQtRole 
AboutRole 
PreferencesRole 
QuitRole 

Definition at line 61 of file qaction.h.

◆ Priority

This enum defines priorities for actions in user interface.

\value LowPriority The action should not be prioritized in the user interface.

\value NormalPriority

\value HighPriority The action should be prioritized in the user interface.

See also
priority
Enumerator
LowPriority 
NormalPriority 
HighPriority 

Definition at line 64 of file qaction.h.

Constructor & Destructor Documentation

◆ QAction() [1/4]

QAction::QAction ( QObject * parent = nullptr)
explicit

Constructs an action with parent.

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

Note
The parent argument is optional since Qt 5.7.

Definition at line 230 of file qaction.cpp.

◆ QAction() [2/4]

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

Constructs an action with some text and parent.

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

A stripped version of text (for example, "\&Menu Option..." becomes "Menu Option") will be used for tooltips and icon text unless you specify a different text using setToolTip() or setIconText(), respectively.

See also
text

Definition at line 246 of file qaction.cpp.

References d, and text.

◆ QAction() [3/4]

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

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.

A stripped version of text (for example, "\&Menu Option..." becomes "Menu Option") will be used for tooltips and icon text unless you specify a different text using setToolTip() or setIconText(), respectively.

See also
text, icon

Definition at line 264 of file qaction.cpp.

References d, and icon.

◆ ~QAction()

QAction::~QAction ( )

Destroys the object and frees allocated resources.

Definition at line 447 of file qaction.cpp.

References d, QGuiApplicationPrivate::instance(), and qApp.

+ Here is the call graph for this function:

◆ QAction() [4/4]

QAction::QAction ( QActionPrivate & dd,
QObject * parent )
protected

Definition at line 274 of file qaction.cpp.

References d, and QObject::parent().

+ Here is the call graph for this function:

Member Function Documentation

◆ actionGroup()

QActionGroup * QAction::actionGroup ( ) const

Returns the action group for this action.

If no action group manages this action, then \nullptr will be returned.

See also
QActionGroup, setActionGroup()

Definition at line 493 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::copyActionToPlatformItem(), and QMenu::initStyleOption().

+ Here is the caller graph for this function:

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

References d, emit, QActionGroup::Exclusive, Hover, hovered(), setChecked(), Trigger, and triggered().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ associatedObjects()

QList< QObject * > QAction::associatedObjects ( ) const
Since
6.0 Returns a list of objects this action has been added to.
See also
QWidget::addAction(), QGraphicsWidget::addAction()

Definition at line 505 of file qaction.cpp.

References d.

Referenced by QGraphicsWidget::insertAction(), QWidget::insertAction(), QGraphicsWidget::removeAction(), QWidget::removeAction(), and waitForPopup().

+ Here is the caller graph for this function:

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

Referenced by QActionGroup::addAction(), QMenuPrivate::init(), and QActionGroup::removeAction().

+ Here is the caller graph for this function:

◆ checkableChanged

void QAction::checkableChanged ( bool checkable)
signal

Referenced by setCheckable().

+ Here is the caller graph for this function:

◆ data()

QVariant QAction::data ( ) const

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

See also
setData()

Definition at line 1056 of file qaction.cpp.

References d.

Referenced by QCalendarWidgetPrivate::_q_monthChanged(), QDialog::contextMenuEvent(), and setData().

+ Here is the caller graph for this function:

◆ enabledChanged

void QAction::enabledChanged ( bool enabled)
signal

◆ event()

bool QAction::event ( QEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented from QObject.

Reimplemented in QWidgetAction.

Definition at line 1027 of file qaction.cpp.

References QEvent::ActionChanged, activate(), d, QObject::event(), QKeySequence::NativeText, Q_ASSERT_X, qWarning, QCoreApplication::sendEvent(), QEvent::Shortcut, Trigger, and QEvent::type().

Referenced by QWidgetAction::event(), and QQuickParentAnimation::transition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ font()

QFont QAction::font ( ) const

Definition at line 437 of file qaction.cpp.

References d.

◆ hover

void QAction::hover ( )
inlineslot

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

Definition at line 211 of file qaction.h.

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

Referenced by QWidgetPlatformMenuItem::QWidgetPlatformMenuItem(), activate(), QActionGroup::addAction(), QMenuPrivate::insertActionInPlatformMenu(), and QActionGroup::removeAction().

+ Here is the caller graph for this function:

◆ icon()

QIcon QAction::icon ( ) const

Definition at line 554 of file qaction.cpp.

References d.

◆ iconText()

QString QAction::iconText ( ) const

Definition at line 661 of file qaction.cpp.

References d, and qt_strippedText().

+ Here is the call graph for this function:

◆ isCheckable()

bool QAction::isCheckable ( ) const

Definition at line 847 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::copyActionToPlatformItem(), QMenu::initStyleOption(), operator<<(), QToolButton::setDefaultAction(), and QMenuPrivate::updateActionRects().

+ Here is the caller graph for this function:

◆ isChecked()

bool QAction::isChecked ( ) const

Definition at line 892 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::copyActionToPlatformItem(), QMenu::initStyleOption(), QPrintPreviewDialogPrivate::isFitting(), operator<<(), QToolButton::setDefaultAction(), QPrintPreviewDialogPrivate::setFitting(), QFileDialogPrivate::showHeader(), and QFileDialogPrivate::showHidden().

+ Here is the caller graph for this function:

◆ isEnabled()

◆ isIconVisibleInMenu()

bool QAction::isIconVisibleInMenu ( ) const

Definition at line 1254 of file qaction.cpp.

References Qt::AA_DontShowIconsInMenus, d, and QCoreApplication::testAttribute().

Referenced by QMenuPrivate::copyActionToPlatformItem(), and QMenu::initStyleOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSeparator()

bool QAction::isSeparator ( ) const

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

See also
setSeparator()

Definition at line 585 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::activateAction(), QMenuBarPrivate::calcActionRects(), QMenuPrivate::copyActionToPlatformItem(), QMenuPrivate::getLastVisibleAction(), QMenu::initStyleOption(), QMenu::isEmpty(), QMenu::keyPressEvent(), QMenu::mouseMoveEvent(), QMenuSloppyState::processMouseEvent(), QMenuPrivate::scrollMenu(), QMenuPrivate::setCurrentAction(), QMenuPrivate::setFirstActionActive(), QMenuPrivate::setSyncAction(), and QMenuPrivate::updateActionRects().

+ Here is the caller graph for this function:

◆ isShortcutVisibleInContextMenu()

bool QAction::isShortcutVisibleInContextMenu ( ) const

Definition at line 1290 of file qaction.cpp.

References Qt::AA_DontShowShortcutsInContextMenus, d, and QCoreApplication::testAttribute().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isVisible()

bool QAction::isVisible ( ) const

Definition at line 1018 of file qaction.cpp.

References d.

Referenced by QMenuBarPrivate::calcActionRects(), QMenuPrivate::copyActionToPlatformItem(), QMenuBarPrivate::copyActionToPlatformMenu(), QMenuPrivate::getLastVisibleAction(), QMenu::isEmpty(), QToolBarItem::isEmpty(), QMenuBar::mouseMoveEvent(), QMenuBar::mousePressEvent(), operator<<(), and QMenuPrivate::updateActionRects().

+ Here is the caller graph for this function:

◆ menu()

template<typename T = QMenu*>
QMenu * QAction::menu ( ) const
inline

Returns the menu contained by this action.

In widget applications, 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(), QMenu::menuInAction()

Definition at line 186 of file qaction.h.

Referenced by QMenuBarPrivate::_q_internalShortcutActivated(), QMenuPrivate::copyActionToPlatformItem(), QMenu::event(), QMenuBarPrivate::getPlatformMenu(), QMenu::initStyleOption(), QMenu::mouseReleaseEvent(), QMenuBar::mouseReleaseEvent(), QMenuBarPrivate::popupAction(), QMenuPrivate::popupAction(), QToolButton::setDefaultAction(), and QMenuPrivate::setSyncAction().

+ Here is the caller graph for this function:

◆ menuRole()

QAction::MenuRole QAction::menuRole ( ) const

Definition at line 1190 of file qaction.cpp.

References d.

◆ priority()

QAction::Priority QAction::priority ( ) const

Definition at line 807 of file qaction.cpp.

References d.

◆ resetEnabled

void QAction::resetEnabled ( )
slot

Definition at line 962 of file qaction.cpp.

References d.

◆ 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, actionGroup()

Definition at line 473 of file qaction.cpp.

References d.

◆ setCheckable()

void QAction::setCheckable ( bool b)

Definition at line 832 of file qaction.cpp.

References checkableChanged(), d, emit, and toggled().

Referenced by QFileDialogPrivate::createMenuActions(), QDockWidgetPrivate::init(), QToolBarPrivate::init(), QWidgetPlatformMenuItem::setCheckable(), and QPrintPreviewDialogPrivate::setupActions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setChecked

void QAction::setChecked ( bool b)
slot

Definition at line 877 of file qaction.cpp.

References d, emit, and toggled().

Referenced by QPrintPreviewDialogPrivate::_q_pageSetup(), activate(), QFileDialogPrivate::restoreWidgetState(), Viewer::setBrightness(), QWidgetPlatformMenuItem::setChecked(), QPrintPreviewDialogPrivate::setFitting(), QPrintPreviewDialogPrivate::setupActions(), and toggle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setData()

void QAction::setData ( const QVariant & data)

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

See also
data()

Definition at line 1067 of file qaction.cpp.

References d, and data().

Referenced by QCalendarWidgetPrivate::createNavigationBar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDisabled

void QAction::setDisabled ( bool b)
inlineslot

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

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

Definition at line 216 of file qaction.h.

◆ setEnabled

◆ setFont()

void QAction::setFont ( const QFont & font)

Definition at line 426 of file qaction.cpp.

References d, and font.

Referenced by QWidgetPlatformMenuItem::setFont().

+ Here is the caller graph for this function:

◆ setIcon()

void QAction::setIcon ( const QIcon & icon)

Definition at line 547 of file qaction.cpp.

References d, and icon.

Referenced by qt_setupActionIcon(), setActionIcon(), and QWidgetPlatformMenuItem::setIcon().

+ Here is the caller graph for this function:

◆ setIconText()

void QAction::setIconText ( const QString & text)

Definition at line 651 of file qaction.cpp.

References d, and text.

◆ setIconVisibleInMenu()

void QAction::setIconVisibleInMenu ( bool visible)

Definition at line 1240 of file qaction.cpp.

References Qt::AA_DontShowIconsInMenus, d, QCoreApplication::testAttribute(), and visible.

+ Here is the call graph for this function:

◆ setMenu()

template<typename T = QMenu*>
void QAction::setMenu ( T m)
inline

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

Definition at line 191 of file qaction.h.

Referenced by QMenuPrivate::init(), and QWidgetPlatformMenuItem::setMenu().

+ Here is the caller graph for this function:

◆ setMenuRole()

void QAction::setMenuRole ( MenuRole menuRole)

Definition at line 1180 of file qaction.cpp.

References d, and menuRole.

Referenced by QDockWidgetPrivate::init(), and QWidgetPlatformMenuItem::setRole().

+ Here is the caller graph for this function:

◆ setPriority()

void QAction::setPriority ( Priority priority)

Definition at line 797 of file qaction.cpp.

References d, and priority.

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

Definition at line 569 of file qaction.cpp.

References d.

Referenced by QMenu::addSection(), QMenu::addSection(), QMenu::addSeparator(), QToolBar::addSeparator(), QMenu::insertSection(), QMenu::insertSection(), QMenu::insertSeparator(), QMenuBar::insertSeparator(), QToolBar::insertSeparator(), and QWidgetPlatformMenuItem::setIsSeparator().

+ Here is the caller graph for this function:

◆ setShortcutVisibleInContextMenu()

void QAction::setShortcutVisibleInContextMenu ( bool show)

Definition at line 1276 of file qaction.cpp.

References Qt::AA_DontShowShortcutsInContextMenus, d, QCoreApplication::testAttribute(), and visible.

+ Here is the call graph for this function:

◆ setStatusTip()

void QAction::setStatusTip ( const QString & statusTip)

Definition at line 712 of file qaction.cpp.

References d.

◆ setText()

void QAction::setText ( const QString & text)

Definition at line 611 of file qaction.cpp.

References d, and text.

Referenced by QDockWidgetPrivate::init(), QFileDialogPrivate::retranslateStrings(), and QWidgetPlatformMenuItem::setText().

+ Here is the caller graph for this function:

◆ setToolTip()

void QAction::setToolTip ( const QString & tip)

Definition at line 680 of file qaction.cpp.

References d.

◆ setVisible

void QAction::setVisible ( bool b)
slot

Definition at line 990 of file qaction.cpp.

References d.

Referenced by QWidgetAction::setDefaultWidget(), QWidgetPlatformMenu::setVisible(), QWidgetPlatformMenuItem::setVisible(), and QMdiSubWindowPrivate::setVisible().

+ Here is the caller graph for this function:

◆ setWhatsThis()

void QAction::setWhatsThis ( const QString & what)

Definition at line 752 of file qaction.cpp.

References d.

◆ showStatusText()

bool QAction::showStatusText ( QObject * object = nullptr)

Updates the relevant status bar for the UI represented by object by sending a QStatusTipEvent.

Returns true if an event was sent, otherwise returns false.

If a null widget is specified, the event is sent to the action's parent.

See also
statusTip

Definition at line 736 of file qaction.cpp.

References d, and statusTip.

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

+ Here is the caller graph for this function:

◆ statusTip()

QString QAction::statusTip ( ) const

Definition at line 722 of file qaction.cpp.

References d.

◆ text()

QString QAction::text ( ) const

Definition at line 621 of file qaction.cpp.

References d, and QString::replace().

+ Here is the call graph for this function:

◆ toggle

void QAction::toggle ( )
slot

This is a convenience function for the \l checked property.

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

Definition at line 859 of file qaction.cpp.

References d, and setChecked().

+ Here is the call graph for this function:

◆ 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. As setChecked() changes the QAction, it emits changed() in addition to toggled().

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

See also
activate(), triggered(), checked

Referenced by setCheckable(), and setChecked().

+ Here is the caller graph for this function:

◆ toolTip()

QString QAction::toolTip ( ) const

Definition at line 690 of file qaction.cpp.

References d, and qt_strippedText().

+ Here is the call graph for this function:

◆ trigger

void QAction::trigger ( )
inlineslot

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

Definition at line 210 of file qaction.h.

References Trigger.

Referenced by QMenuPrivate::insertActionInPlatformMenu().

+ Here is the caller graph for this function:

◆ 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
activate(), toggled(), checked

Referenced by QWidgetPlatformMenuItem::QWidgetPlatformMenuItem(), QToolButton::actionEvent(), activate(), QWidget::addAction(), QWidget::addAction(), QActionGroup::addAction(), QFileDialogPrivate::createMenuActions(), QUndoGroup::createRedoAction(), QLineEdit::createStandardContextMenu(), QUndoGroup::createUndoAction(), QDockWidgetPrivate::init(), and QActionGroup::removeAction().

+ Here is the caller graph for this function:

◆ visibleChanged

void QAction::visibleChanged ( )
signal

◆ whatsThis()

QString QAction::whatsThis ( ) const

Definition at line 762 of file qaction.cpp.

References d.

Friends And Related Symbol Documentation

◆ QActionGroup

friend class QActionGroup
friend

Definition at line 230 of file qaction.h.

◆ QGraphicsWidget

friend class QGraphicsWidget
friend

Definition at line 235 of file qaction.h.

◆ QMenu

friend class QMenu
friend

Definition at line 232 of file qaction.h.

◆ QMenuPrivate

friend class QMenuPrivate
friend

Definition at line 233 of file qaction.h.

◆ QToolButton

friend class QToolButton
friend

Definition at line 234 of file qaction.h.

◆ QWidget

friend class QWidget
friend

Definition at line 231 of file qaction.h.

Property Documentation

◆ checkable

QAction::checkable
readwrite

whether the action is a checkable action

A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.

In some situations, the state of one toggle action should depend on the state of others. For example, "Left Align", "Center" and "Right Align" toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a QActionGroup with the QActionGroup::exclusive property set to true.

See also
setChecked()

Definition at line 34 of file qaction.h.

◆ checked

QAction::checked
readwrite

whether the action is checked.

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

Note
The notifier signal for this property is toggled(). As toggling a QAction changes its state, it will also emit a changed() signal.
See also
checkable, toggled()

Definition at line 35 of file qaction.h.

◆ enabled

QAction::enabled
readwrite

whether the action is enabled

Disabled actions cannot be chosen by the user. They do not disappear from menus or toolbars, but they are displayed in a way which indicates that they are unavailable. For example, they might be displayed using only shades of gray.

\uicontrol{What's This?} help on disabled actions is still available, provided that the QAction::whatsThis property is set.

An action will be disabled when all widgets to which it is added (with QWidget::addAction()) are disabled or not visible. When an action is disabled, it is not possible to trigger it through its shortcut.

By default, this property is true (actions are enabled).

See also
text

Definition at line 36 of file qaction.h.

◆ font

QAction::font
readwrite

the action's font

The font property is used to render the text set on the QAction. The font 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
setText()

Definition at line 44 of file qaction.h.

Referenced by QMenuPrivate::copyActionToPlatformItem(), QMenu::initStyleOption(), QToolButton::setDefaultAction(), and setFont().

◆ icon

QAction::icon
readwrite

the action's icon

In toolbars, the icon is used as the tool button icon; in menus, it is displayed to the left of the menu text. There is no default icon.

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

Definition at line 38 of file qaction.h.

Referenced by QAction(), QMenuBarPrivate::calcActionRects(), QMenuPrivate::copyActionToPlatformItem(), QMenu::initStyleOption(), QMenuBar::initStyleOption(), QToolButton::setDefaultAction(), setIcon(), and QMenuPrivate::updateActionRects().

◆ iconText

QAction::iconText
readwrite

the action's descriptive icon text

If QToolBar::toolButtonStyle is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button.

It also serves as the default text in menus and tooltips if the action has not been defined with setText() or setToolTip(), and will also be used in toolbar buttons if no icon has been defined using setIcon().

If the icon text is not explicitly set, the action's normal text will be used for the icon text.

By default, this property contains an empty string.

See also
setToolTip(), setStatusTip()

Definition at line 40 of file qaction.h.

Referenced by QToolButton::setDefaultAction().

◆ iconVisibleInMenu

QAction::iconVisibleInMenu
readwrite

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

In some applications, it may make sense to have actions with icons in the toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it is false, it is not shown.

The default is to follow whether the Qt::AA_DontShowIconsInMenus attribute is set for the application. Explicitly settings this property overrides the presence (or absence) of the attribute.

For example:

QApplication app(argc, argv);
app.setAttribute(Qt::AA_DontShowIconsInMenus); // Icons are *no longer shown* in menus
// ...
// ...
myAction->setIcon(SomeIcon);
myAction->setIconVisibleInMenu(true); // Icon *will* be shown in menus for *this* action.
void setIconVisibleInMenu(bool visible)
Definition qaction.cpp:1240
void setIcon(const QIcon &icon)
Definition qaction.cpp:547
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
@ AA_DontShowIconsInMenus
Definition qnamespace.h:427
QAction * myAction
See also
icon, QCoreApplication::setAttribute()

Definition at line 53 of file qaction.h.

◆ menuRole

QAction::menuRole
readwrite

the action's menu role

This indicates what role the action serves in the application menu on \macos. By default all actions have the TextHeuristicRole, which means that the action is added based on its text (see QMenuBar for more information).

The menu role can only be changed before the actions are put into the menu bar in \macos (usually just before the first application window is shown).

Definition at line 52 of file qaction.h.

Referenced by QMenuPrivate::copyActionToPlatformItem(), operator<<(), and setMenuRole().

◆ priority

QAction::priority
readwrite

the actions's priority in the user interface.

This property can be set to indicate how the action should be prioritized in the user interface.

For instance, when toolbars have the Qt::ToolButtonTextBesideIcon mode set, then actions with LowPriority will not show the text labels.

Definition at line 57 of file qaction.h.

Referenced by setPriority().

◆ shortcutVisibleInContextMenu

QAction::shortcutVisibleInContextMenu
readwrite

Whether or not an action should show a shortcut in a context menu.

In some applications, it may make sense to have actions with shortcuts in context menus. If true, the shortcut (if valid) is shown when the action is shown via a context menu, when it is false, it is not shown.

The default is to follow whether the Qt::AA_DontShowShortcutsInContextMenus attribute is set for the application. Explicitly setting this property overrides the attribute.

See also
shortcut, QCoreApplication::setAttribute()

Definition at line 55 of file qaction.h.

◆ statusTip

QAction::statusTip
readwrite

the action's status tip

The status tip is displayed on all status bars provided by the action's top-level parent widget.

By default, this property contains an empty string.

See also
setToolTip(), showStatusText()

Definition at line 42 of file qaction.h.

Referenced by QToolButton::setDefaultAction(), and showStatusText().

◆ text

QAction::text
readwrite

the action's descriptive text

If the action is added to a menu, the menu option will consist of the icon (if there is one), the text, and the shortcut (if there is one). If the text is not explicitly set in the constructor, or by using setText(), the action's description icon text will be used as text. There is no default text.

Certain UI elements, such as menus or buttons, can use '&' in front of a character to automatically create a mnemonic (a shortcut) for that character. For example, "&File" for a menu will create the shortcut \uicontrol Alt+F, which will open the File menu. "E&xit" will create the shortcut \uicontrol Alt+X for a button, or in a menu allow navigating to the menu item by pressing "x". (use '&&' to display an actual ampersand). The widget might consume and perform an action on a given shortcut.

See also
iconText

Definition at line 39 of file qaction.h.

Referenced by QAction(), QCalendarWidgetPrivate::_q_monthChanged(), QMenuBarPrivate::calcActionRects(), QMenuPrivate::copyActionToPlatformItem(), QMenuBarPrivate::copyActionToPlatformMenu(), QMenu::initStyleOption(), QMenuBar::initStyleOption(), QMenu::keyPressEvent(), QMenuBar::keyPressEvent(), operator<<(), setIconText(), setText(), QMenuPrivate::updateActionRects(), and QMenuBarPrivate::updateGeometries().

◆ toolTip

QAction::toolTip
readwrite

the action's tooltip

This text is used for the tooltip. If no tooltip is specified, the action's text is used.

By default, this property contains the action's text.

See also
setStatusTip(), setShortcut()

Definition at line 41 of file qaction.h.

Referenced by operator<<(), and QToolButton::setDefaultAction().

◆ visible

QAction::visible
readwrite

whether the action can be seen (e.g.

in menus and toolbars)

If visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.

Actions which are not visible are not grayed out; they do not appear at all.

By default, this property is true (actions are visible).

Definition at line 51 of file qaction.h.

Referenced by setIconVisibleInMenu(), and setShortcutVisibleInContextMenu().

◆ whatsThis

QAction::whatsThis
readwrite

the action's "What's This?" help text

The "What's This?" text is used to provide a brief description of the action. The text may contain rich text. There is no default "What's This?" text.

See also
QWhatsThis

Definition at line 43 of file qaction.h.

Referenced by QMenuPrivate::activateAction(), QMenu::event(), and QToolButton::setDefaultAction().


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