QAction(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

🌸 NAME 🌸

okay bestie, so this whole page is QAction(3qt) and it's literally all about QAction β€” the abstract user interface action that can appear both in menus and tool bars. one action, two homes, zero drama. πŸ’…


✨ SYNOPSIS ✨

#include <qaction.h>

Inherits QObject.

Inherited by QActionGroup.

🫢 Public Members 🫢

  • QAction ( QObject * parent, const char * name = 0 )
  • QAction ( const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0 )
  • QAction ( const QIconSet & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0 )
  • QAction ( const QString & text, const QIconSet & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0, bool toggle = FALSE ) β€” (obsolete)
  • QAction ( const QString & text, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0, bool toggle = FALSE ) β€” (obsolete)
  • QAction ( QObject * parent, const char * name, bool toggle ) β€” (obsolete)
  • ~QAction ()
  • virtual void setIconSet ( const QIconSet & )
  • QIconSet iconSet () const
  • virtual void setText ( const QString & )
  • QString text () const
  • virtual void setMenuText ( const QString & )
  • QString menuText () const
  • virtual void setToolTip ( const QString & )
  • QString toolTip () const
  • virtual void setStatusTip ( const QString & )
  • QString statusTip () const
  • virtual void setWhatsThis ( const QString & )
  • QString whatsThis () const
  • virtual void setAccel ( const QKeySequence & key )
  • QKeySequence accel () const
  • virtual void setToggleAction ( bool )
  • bool isToggleAction () const
  • bool isOn () const
  • bool isEnabled () const
  • bool isVisible () const
  • virtual bool addTo ( QWidget * w )
  • virtual bool removeFrom ( QWidget * w )

πŸ’… Public Slots πŸ’…

  • void activate ()
  • void toggle ()
  • virtual void setOn ( bool )
  • virtual void setEnabled ( bool )
  • void setDisabled ( bool disable )
  • void setVisible ( bool )

πŸ“£ Signals πŸ“£

  • void activated ()
  • void toggled ( bool on )

🌈 Properties 🌈

  • QKeySequence accel β€” the action's accelerator key
  • bool enabled β€” whether the action is enabled
  • QIconSet iconSet β€” the action's icon
  • QString menuText β€” the action's menu text
  • bool on β€” whether a toggle action is on
  • QString statusTip β€” the action's status tip
  • QString text β€” the action's descriptive text
  • bool toggleAction β€” whether the action is a toggle action
  • QString toolTip β€” the action's tool tip
  • bool visible β€” whether the action can be seen (e.g. in menus and toolbars)
  • QString whatsThis β€” the action's "What's This?" help text

🧚 Protected Members 🧚

  • virtual void addedTo ( QWidget * actionWidget, QWidget * container )
  • virtual void addedTo ( int index, QPopupMenu * menu )

πŸ’– DESCRIPTION πŸ’–

The QAction class provides an abstract user interface action that can appear both in menus and tool bars.

okay so real talk: in GUI apps, like, SO many commands can get triggered three whole ways β€” a menu option, a toolbar button, and a keyboard accelerator. And the whole point is that the same action has to happen no matter which path the user took, plus your menu and toolbar are supposed to stay in sync with each other. So it just makes sense to represent a command as an action. Add one action to a menu and a toolbar and it keeps them synced automatically. like, if the user presses a Bold toolbar button, the Bold menu item automatically gets checked too. automatic. ✨

A QAction can hold an icon, a menu text, an accelerator, a status text, a whats this text, and a tool tip. Most of these can be set right in the constructor. You can also set them independently with setIconSet(), setText(), setMenuText(), setToolTip(), setStatusTip(), setWhatsThis(), and setAccel(). pick your fighter. πŸŽ€

An action can be a toggle action (think: a Bold toolbar button) or a command action (think: 'Open File' that pops open a file dialog). Toggle actions emit the toggled() signal whenever their state flips. Both command and toggle actions emit the activated() signal when they're invoked. Use setToggleAction() to set an action's toggled status, and isToggleAction() to find out if it is a toggle action. A toggle action can be "on" β€” isOn() returns TRUE β€” or "off" β€” isOn() returns FALSE. no in-between, bestie. πŸ’€

Actions get added to widgets (menus or toolbars) with addTo(), and removed with removeFrom().

Once you've made a QAction, you should add it to the relevant menu and toolbar, then connect it to the slot that'll actually do the thing. for example:

        fileOpenAction = new QAction( QPixmap( fileopen ), "&Open...",
                                      CTRL+Key_O, this, "open" );
        connect( fileOpenAction, SIGNAL( activated() ) , this, SLOT( choose() ) );

We create a "File Save" action with a menu text of "&Save" and Ctrl+S as the keyboard accelerator. We connect the fileSaveAction's activated() signal to our own save() slot. note that at this point there's no menu or toolbar action yet β€” we'll add them next:

        QToolBar * fileTools = new QToolBar( this, "file operations" );

        fileSaveAction->addTo( fileTools );

        QPopupMenu * file = new QPopupMenu( this );
        menuBar()->insertItem( "&File", file );

        fileSaveAction->addTo( file );

We create a toolbar and add our fileSaveAction to it. similarly, we create a menu, add a top-level menu item, and add our fileSaveAction. πŸ’…

We recommend that actions are created as children of the window they're used in. In most cases, actions will be children of the application's main window.

⚠️ To prevent recursion, don't create an action as a child of a widget that the action is later added to.

See also Main Window and Related Classes and Basic Widgets.


πŸ’œ MEMBER FUNCTION DOCUMENTATION πŸ’œ

QAction::QAction ( QObject * parent, const char * name = 0 )

Constructs an action called name with parent parent.

If parent is a QActionGroup, the new action inserts itself into parent.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

⚠️ Warning: To prevent recursion, don't create an action as a child of a widget that the action is later added to.

QAction::QAction ( const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0 )

This constructor gives you an icon-less action with the menu text menuText and keyboard accelerator accel. It's a child of parent and it's called name.

If parent is a QActionGroup, the action automatically becomes a member of it.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The action uses a stripped version of menuText (like, "&Menu Option..." becomes "Menu Option") as descriptive text for toolbuttons. You can override that by setting a specific description with setText(). The same text and accel get used for tool tips and status tips unless you hand over text for those with setToolTip() and setStatusTip().

Call setToggleAction(TRUE) to make the action a toggle action.

⚠️ Warning: To prevent recursion, don't create an action as a child of a widget that the action is later added to.

QAction::QAction ( const QIconSet & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0 )

This constructor creates an action with these properties: the icon or iconset icon, the menu text menuText, and keyboard accelerator accel. It's a child of parent and it's called name.

If parent is a QActionGroup, the action automatically becomes a member of it.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The action uses a stripped version of menuText (like, "&Menu Option..." becomes "Menu Option") as descriptive text for toolbuttons. You can override that by setting a specific description with setText(). The same text and accel get used for tool tips and status tips unless you hand over text for those with setToolTip() and setStatusTip().

Call setToggleAction(TRUE) to make the action a toggle action.

⚠️ Warning: To prevent recursion, don't create an action as a child of a widget that the action is later added to.

QAction::QAction ( const QString & text, const QIconSet & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0, bool toggle = FALSE )

🚫 This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

This constructor creates an action with these properties: the description text, the icon or iconset icon, the menu text menuText, and keyboard accelerator accel. It's a child of parent and it's called name. If toggle is TRUE, the action will be a toggle action; otherwise it'll be a command action.

If parent is a QActionGroup, the action automatically becomes a member of it.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The text and accel get used for tool tips and status tips unless you provide specific text for those with setToolTip() and setStatusTip().

QAction::QAction ( const QString & text, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0, bool toggle = FALSE )

🚫 This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

This constructor gives you an icon-less action with the description text, the menu text menuText, and the keyboard accelerator accel. Its parent is parent and it's called name. If toggle is TRUE, the action will be a toggle action; otherwise it'll be a command action.

The action automatically becomes a member of parent if parent is a QActionGroup.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

The text and accel get used for tool tips and status tips unless you provide specific text for those with setToolTip() and setStatusTip().

QAction::QAction ( QObject * parent, const char * name, bool toggle )

🚫 This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Constructs an action called name with parent parent.

If toggle is TRUE, the action will be a toggle action; otherwise it'll be a command action.

If parent is a QActionGroup, the new action inserts itself into parent.

For accelerators and status tips to work, parent must either be a widget, or an action group whose parent is a widget.

QAction::~QAction ()

Destroys the object and frees allocated resources. bye bestie, you were iconic. πŸ¦‹

QKeySequence QAction::accel () const

Returns the action's accelerator key. See the "accel" property for details.

void QAction::activate () [slot]

Activates the action and executes all connected slots. This only works for actions that are not toggle actions.

See also toggle().

void QAction::activated () [signal]

Okay bestie, this signal fires when an action gets activated by the user β€” like when they click a menu option, hit a toolbar button, or press that action's accelerator key combo. ✨

So if you're doing command actions, connect to this one. If you're doing toggle actions, connect to toggled() instead. 🫢

Examples:


bool QAction::addTo ( QWidget * w ) [virtual]

Adds this action to widget w. πŸ’…

Right now actions can be added to QToolBar and QPopupMenu widgets. That's the whole guest list.

An action added to a tool bar automatically shows up as a tool button; an action added to a pop up menu appears as a menu option. Iconic behaviour, honestly.

addTo() returns TRUE if the action was added successfully and FALSE otherwise. (If w is not a QToolBar or QPopupMenu the action will not be added and FALSE will be returned. No notes.)

See also removeFrom().

Examples:

Reimplemented in QActionGroup.


void QAction::addedTo ( QWidget * actionWidget, QWidget * container ) [virtual protected]

This function is called from the addTo() function when it has created a widget (actionWidget) for the action in the container. It's giving behind-the-scenes main character energy. πŸŽ€


void QAction::addedTo ( int index, QPopupMenu * menu ) [virtual protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This function is called from the addTo() function when it has created a menu item at the index position index in the popup menu menu. πŸ¦‹


QIconSet QAction::iconSet () const

Returns the action's icon. See the "iconSet" property for details. ✨


bool QAction::isEnabled () const

Returns TRUE if the action is enabled; otherwise returns FALSE. See the "enabled" property for details.


bool QAction::isOn () const

Returns TRUE if a toggle action is on; otherwise returns FALSE. See the "on" property for details. πŸ’‘


bool QAction::isToggleAction () const

Returns TRUE if the action is a toggle action; otherwise returns FALSE. See the "toggleAction" property for details.


bool QAction::isVisible () const

Returns TRUE if the action can be seen (e.g. in menus and toolbars); otherwise returns FALSE. See the "visible" property for details. πŸ‘€


QString QAction::menuText () const

Returns the action's menu text. See the "menuText" property for details.


bool QAction::removeFrom ( QWidget * w ) [virtual]

Removes the action from widget w. βœ‚οΈ

Returns TRUE if the action was removed successfully; otherwise returns FALSE.

See also addTo().


void QAction::setAccel ( const QKeySequence & key ) [virtual]

Sets the action's accelerator key to key. See the "accel" property for details. ⌨️


void QAction::setDisabled ( bool disable ) [slot]

Disables the action if disable is TRUE; otherwise enables the action.

See the enabled documentation for more information. 🚫


void QAction::setEnabled ( bool ) [virtual slot]

Sets whether the action is enabled. See the "enabled" property for details.


void QAction::setIconSet ( const QIconSet & ) [virtual]

Sets the action's icon. See the "iconSet" property for details. 🌸


void QAction::setMenuText ( const QString & ) [virtual]

Sets the action's menu text. See the "menuText" property for details.


void QAction::setOn ( bool ) [virtual slot]

Sets whether a toggle action is on. See the "on" property for details. πŸ”›


void QAction::setStatusTip ( const QString & ) [virtual]

Sets the action's status tip. See the "statusTip" property for details.


void QAction::setText ( const QString & ) [virtual]

Sets the action's descriptive text. See the "text" property for details. πŸ“


void QAction::setToggleAction ( bool ) [virtual]

Sets whether the action is a toggle action. See the "toggleAction" property for details.


void QAction::setToolTip ( const QString & ) [virtual]

Sets the action's tool tip. See the "toolTip" property for details. πŸ’¬


void QAction::setVisible ( bool ) [slot]

Sets whether the action can be seen (e.g. in menus and toolbars). See the "visible" property for details.


void QAction::setWhatsThis ( const QString & ) [virtual]

Sets the action's "What's This?" help text. See the "whatsThis" property for details. ❓


QString QAction::statusTip () const

Returns the action's status tip. See the "statusTip" property for details.


QString QAction::text () const

Returns the action's descriptive text. See the "text" property for details. ✨


void QAction::toggle () [slot]

Toggles the state of a toggle action. Flip it, periodt. πŸ”

See also on, activate(), toggled(), and toggleAction.


void QAction::toggled ( bool on ) [signal]

This signal is emitted when a toggle action changes state; command actions and QActionGroups don't emit toggled(). Not their vibe, bestie.

The on argument denotes the new state: If on is TRUE the toggle action is switched on, and if on is FALSE the toggle action is switched off.

To trigger a user command depending on whether a toggle action has been switched on or off connect it to a slot that takes a bool to indicate the state, e.g.

QMainWindow * window = new QMainWindow;

QAction * labelonoffaction = new QAction( window, "labelonoff" );

QObject::connect( labelonoffaction, SIGNAL( toggled( bool ) ),
                  window, SLOT( setUsesTextLabel( bool ) ) );

See also activated(), toggleAction, and on.

Example: action/toggleaction/toggleaction.cpp. πŸŽ€


QString QAction::toolTip () const

Returns the action's tool tip. See the "toolTip" property for details.


QString QAction::whatsThis () const

Returns the action's "What's This?" help text. See the "whatsThis" property for details. πŸ’œ


✨ Property Documentation ✨

QKeySequence accel

This property holds the action's accelerator key.

The keycodes can be found in Qt::Key and Qt::Modifier. There is no default accelerator key.

Set this property's value with setAccel() and get this property's value with accel(). ⌨️


bool enabled

This property holds whether the action is enabled.

Disabled actions can't be chosen by the user. They don't disappear from the menu/tool bar but are displayed in a way which indicates that they are unavailable, e.g. they might be displayed grayed out. 😭

What's this? help on disabled actions is still available provided the QAction::whatsThis property is set.

Set this property's value with setEnabled() and get this property's value with isEnabled().


QIconSet iconSet

This property holds the action's icon.

The icon is used as the tool button icon and in the menu to the left of the menu text. There is no default icon.

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

(See the action/toggleaction/toggleaction.cpp example.)

Set this property's value with setIconSet() and get this property's value with iconSet(). πŸ¦‹


QString menuText

This property holds the action's menu text.

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

See also text.

Set this property's value with setMenuText() and get this property's value with menuText().


bool on

This property holds whether a toggle action is on.

This property is always on (TRUE) for command actions and QActionGroups; setOn() has no effect on them. For action's where isToggleAction() is TRUE, this property's default value is off (FALSE).

See also toggleAction.

Set this property's value with setOn() and get this property's value with isOn(). πŸ”›


QString statusTip

This property holds the action's status tip.

The statusTip is displayed on all status bars that this action's toplevel parent widget provides.

If no status tip is defined, the action uses the tool tip text.

There is no default statusTip text.

See also statusTip and toolTip.

Set this property's value with setStatusTip() and get this property's value with statusTip(). πŸ’…


QString text

This property holds the action's descriptive text.

If QMainWindow::usesTextLabel is TRUE, the text appears as a label in the relevant tool button. It also serves as the default text in menus and tool tips if these have not been specifically defined. There is no default text.

See also menuText, toolTip, and statusTip.

Set this property's value with setText() and get this property's value with text(). πŸ“


bool toggleAction

This property holds whether the action is a toggle action.

A toggle action is one which has an on/off state. For example a Bold toolbar button is 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. This property's default 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. πŸ‘‘

Set this property's value with setToggleAction() and get this property's value with isToggleAction().


QString toolTip

This property holds the action's tool tip.

This text is used for the tool tip. If no status tip has been set the tool tip will be used for the status tip.

If no tool tip is specified the action's text is used, and if that hasn't been specified the description text is used as the tool tip text.

There is no default tool tip text.

See also statusTip and accel.

Set this property's value with setToolTip() and get this property's value with toolTip(). πŸ’¬


bool visible

This property holds 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. πŸ’€

Set this property's value with setVisible() and get this property's value with isVisible().


QString whatsThis

This property holds the action's "What's This?" help text.

The whats this text is used to provide a brief description of the action. The text may contain rich text (HTML-like tags β€” see QStyleSheet for the list of supported tags). There is no default "What's This" text.

See also QWhatsThis.

Set this property's value with setWhatsThis() and get this property's value with whatsThis(). ❓


πŸ‘€ SEE ALSO πŸ‘€


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


✍️ AUTHOR ✍️

Generated automatically from the source code.

πŸ› BUGS (aka bestie found a glitch) πŸ›

okay so. if you find a bug in Qt, pls pls pls report it the way it says over at http://doc.trolltech.com/bughowto.html. like actually do it, because good bug reports are the whole entire vibe and they help us help you. thank u πŸ«ΆπŸ’–


the ✨definitive✨ Qt documentation is in HTML format, it lives at $QTDIR/doc/html, and you can read it with Qt Assistant or honestly just any web browser, whatever's giving. this man page? it's a convenience thing for the girlies who prefer man pages, lowkey iconic of you, but ngl this format is not officially supported by Trolltech. just so we're clear on that. πŸ’…


and hey β€” if you spot an error in this manual page specifically, report it to qt-bugs@trolltech.com. please please include the name of the manual page (qaction.3qt) and the Qt version (3.3.8) or else we're just out here guessing and that's not the energy we want. πŸ™ˆ


fr fr, bug reports are a love language. be specific, be kind, and the maintainers will absolutely eat. πŸ”₯πŸ‘‘

that's the whole page bestie, we did it!! πŸŽ€βœ¨ this one came to you courtesy of Trolltech AS, dated 2 February 2007, and it's the man page for QAction(3qt) β€” version 3.3.8 era, which is so vintage of it. go forth and slay your menus, you absolute main character. πŸ’œπŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from