
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQ3Action class provides an abstract user interface action that can appear both in menus and tool bars.More...
| Header: | #include <Q3Action> |
| Inherits: | QObject |
| Inherited By: |
|
| Q3Action(QObject * parent, const char * name = 0) | |
| Q3Action(const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0) | |
| Q3Action(const QIcon & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0) | |
| Q3Action(const QString & text, const QIcon & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0, bool toggle = false) | |
| Q3Action(const QString & text, const QString & menuText, QKeySequence accel, QObject * parent, const char * name = 0, bool toggle = false) | |
| Q3Action(QObject * parent, const char * name, bool toggle) | |
| ~Q3Action() | |
| QKeySequence | accel() const |
| virtual bool | addTo(QWidget * w) |
| QIcon | iconSet() const |
| bool | isEnabled() const |
| bool | isOn() const |
| bool | isToggleAction() const |
| bool | isVisible() const |
| QString | menuText() const |
| virtual bool | removeFrom(QWidget * w) |
| virtual void | setAccel(const QKeySequence & key) |
| virtual void | setIconSet(const QIcon &) |
| virtual void | setMenuText(const QString &) |
| virtual void | setStatusTip(const QString &) |
| virtual void | setText(const QString &) |
| virtual void | setToggleAction(bool) |
| virtual void | setToolTip(const QString &) |
| virtual void | setWhatsThis(const QString &) |
| QString | statusTip() const |
| QString | text() const |
| QString | toolTip() const |
| QString | whatsThis() const |
| void | activate() |
| void | setDisabled(bool disable) |
| virtual void | setEnabled(bool) |
| virtual void | setOn(bool) |
| virtual void | setVisible(bool) |
| void | toggle() |
| virtual void | addedTo(QWidget * actionWidget, QWidget * container) |
| virtual void | addedTo(int index, Q3PopupMenu * menu) |
TheQ3Action class provides an abstract user interface action that can appear both in menus and tool bars.
In GUI applications many commands can be invoked via a menu option, a toolbar button and a keyboard accelerator. Since the same action must be performed regardless of how the action was invoked, and since the menu and toolbar should be kept in sync, it is useful to represent a command as anaction. An action can be added to a menu and a toolbar and will automatically keep them in sync. For example, if the user presses a Bold toolbar button the Bold menu item will automatically be checked.
AQ3Action may contain an icon, a menu text, an accelerator, a status text, a "What's This?" text and a tool tip. Most of these can be set in the constructor. They can also be set independently withsetIconSet(),setText(),setMenuText(),setToolTip(),setStatusTip(),setWhatsThis() andsetAccel().
An action may be a toggle action e.g. a Bold toolbar button, or a command action, e.g. 'Open File' to invoke an open file dialog. Toggle actions emit thetoggled() signal when their state changes. Both command and toggle actions emit theactivated() signal when they are invoked. UsesetToggleAction() to set an action's toggled status. To see if an action is a toggle action useisToggleAction(). A toggle action may be "on",isOn() returns true, or "off",isOn() returns false.
Actions are added to widgets (menus or toolbars) usingaddTo(), and removed usingremoveFrom(). Note that when usingQ3ToolBar andQ3PopupMenu, their actions must be Q3Actions.
Once aQ3Action has been created it should be added to the relevant menu and toolbar and then connected to the slot which will perform the action.
We recommend that actions are created as children of the window that they are 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.
This property holds the action's accelerator key.
The keycodes can be found inQt::Key andQt::Modifier. There is no default accelerator key.
Access functions:
| QKeySequence | accel() const |
| virtual void | setAccel(const QKeySequence & key) |
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 theQ3Action::whatsThis property is set.
Access functions:
| bool | isEnabled() const |
| virtual void | setEnabled(bool) |
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 (QIcon::isNull() is passed into this function, the icon of the action is cleared.
(See the action/toggleaction/toggleaction.cpp example.)
Access functions:
| QIcon | iconSet() const |
| virtual void | setIconSet(const QIcon &) |
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.
Access functions:
| QString | menuText() const |
| virtual void | setMenuText(const QString &) |
See alsotext.
This property holds whether a toggle action is on.
This property is always on (true) for command actions andQ3ActionGroups; setOn() has no effect on them. For action's whereisToggleAction() is true, this property's default value is off (false).
Access functions:
| bool | isOn() const |
| virtual void | setOn(bool) |
See alsotoggleAction.
This property holds the action's status tip.
The statusTip is displayed on all status bars that this action's top-level parent widget provides.
If no status tip is defined, the action uses the tool tip text.
There is no default statusTip text.
Access functions:
| QString | statusTip() const |
| virtual void | setStatusTip(const QString &) |
See alsosetToolTip().
This property holds the action's descriptive text.
Access functions:
| QString | text() const |
| virtual void | setText(const QString &) |
See alsosetMenuText(),setToolTip(), andsetStatusTip().
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 aQ3ActionGroup with theQ3ActionGroup::exclusive property set to true.
Access functions:
| bool | isToggleAction() const |
| virtual void | setToggleAction(bool) |
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.
Access functions:
| QString | toolTip() const |
| virtual void | setToolTip(const QString &) |
See alsosetStatusTip() andsetAccel().
This property holds whether the action can be seen (e.g. in menus and toolbars).
Ifvisible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; ifvisible is false the action cannot be seen or chosen by the user.
Actions which are not visible arenot grayed out; they do not appear at all.
Access functions:
| bool | isVisible() const |
| virtual void | setVisible(bool) |
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 -- seeQStyleSheet for the list of supported tags). There is no default "What's This?" text.
Access functions:
| QString | whatsThis() const |
| virtual void | setWhatsThis(const QString &) |
See alsoQWhatsThis.
Constructs an action calledname with parentparent.
Ifparent is aQ3ActionGroup, the new action inserts itself intoparent.
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.
This constructor results in an icon-less action with the menu textmenuText and keyboard acceleratoraccel. It is a child ofparent and calledname.
Ifparent is aQ3ActionGroup, 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 ofmenuText (e.g. "&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description withsetText(). The same text andaccel will be used for tool tips and status tips unless you provide text for these usingsetToolTip() andsetStatusTip().
CallsetToggleAction(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.
This constructor creates an action with the following properties: the icon or iconicon, the menu textmenuText and keyboard acceleratoraccel. It is a child ofparent and calledname.
Ifparent is aQ3ActionGroup, 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 ofmenuText (e.g. "&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description withsetText(). The same text andaccel will be used for tool tips and status tips unless you provide text for these usingsetToolTip() andsetStatusTip().
CallsetToggleAction(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.
This constructor creates an action with the following properties: the descriptiontext, the icon or iconicon, the menu textmenuText and keyboard acceleratoraccel. It is a child ofparent and calledname. Iftoggle is true the action will be a toggle action, otherwise it will be a command action.
Ifparent is aQ3ActionGroup, 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.
Thetext andaccel will be used for tool tips and status tips unless you provide specific text for these usingsetToolTip() andsetStatusTip().
This constructor results in an icon-less action with the descriptiontext, the menu textmenuText and the keyboard acceleratoraccel. Its parent isparent and it is calledname. Iftoggle is true the action will be a toggle action, otherwise it will be a command action.
The action automatically becomes a member ofparent ifparent is aQ3ActionGroup.
For accelerators and status tips to work,parent must either be a widget, or an action group whose parent is a widget.
Thetext andaccel will be used for tool tips and status tips unless you provide specific text for these usingsetToolTip() andsetStatusTip().
Constructs an action calledname with parentparent.
Iftoggle is true the action will be a toggle action, otherwise it will be a command action.
Ifparent is aQ3ActionGroup, the new action inserts itself intoparent.
For accelerators and status tips to work,parent must either be a widget, or an action group whose parent is a widget.
Destroys the object and frees allocated resources.
[slot]void Q3Action::activate()Activates the action and executes all connected slots. This only works for actions that are not toggle actions.
See alsotoggle().
[signal]void Q3Action::activated()This signal is emitted when an action is activated by the user, e.g. when the user clicks a menu option or a toolbar button or presses an action's accelerator key combination.
Connect to this signal for command actions. Connect to thetoggled() signal for toggle actions.
[virtual]bool Q3Action::addTo(QWidget * w)Adds this action to widgetw.
Currently actions may be added toQ3ToolBar andQ3PopupMenu widgets.
An action added to a tool bar is automatically displayed as a tool button; an action added to a pop up menu appears as a menu option.
addTo() returns true if the action was added successfully and false otherwise. (Ifw is not aQ3ToolBar orQ3PopupMenu the action will not be added and false will be returned.)
See alsoremoveFrom().
[virtual protected]void Q3Action::addedTo(QWidget * actionWidget,QWidget * container)This function is called from theaddTo() function when it has created a widget (actionWidget) for the action in thecontainer.
[virtual protected]void Q3Action::addedTo(int index,Q3PopupMenu * menu)This is an overloaded function.
This function is called from theaddTo() function when it has created a menu item at the index positionindex in the popup menumenu.
[virtual]bool Q3Action::removeFrom(QWidget * w)Removes the action from widgetw.
Returns true if the action was removed successfully; otherwise returns false.
See alsoaddTo().
[slot]void Q3Action::setDisabled(bool disable)Disables the action ifdisable is true; otherwise enables the action.
See theenabled documentation for more information.
[slot]void Q3Action::toggle()Toggles the state of a toggle action.
See alsoon,activate(),toggled(), andisToggleAction().
[signal]void Q3Action::toggled(bool on)This signal is emitted when a toggle action changes state; command actions andQ3ActionGroups don't emit toggled().
Theon argument denotes the new state: Ifon is true the toggle action is switched on, and ifon 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.
See alsoactivated(),setToggleAction(), andsetOn().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.