Q3Action 类

The Q3Action 类提供可以出现在菜单和工具栏中的抽象用户界面动作。 更多...

头: #include <Q3Action>
继承: QObject
继承者: Q3ActionGroup

特性

公共函数

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

信号

void activated ()
void toggled (bool on )

保护函数

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

额外继承成员

详细描述

The Q3Action 类提供可以出现在菜单和工具栏中的抽象用户界面动作。

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 an action . 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.

A Q3Action 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 with setIconSet (), setText (), setMenuText (), setToolTip (), setStatusTip (), setWhatsThis () 和 setAccel ().

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 the toggled () signal when their state changes. Both command and toggle actions emit the activated () signal when they are invoked. Use setToggleAction () to set an action's toggled status. To see if an action is a toggle action use isToggleAction (). A toggle action may be "on", isOn () returns true, or "off", isOn () 返回 false。

Actions are added to widgets (menus or toolbars) using addTo (), and removed using removeFrom (). Note that when using Q3ToolBar and Q3PopupMenu , their actions must be Q3Actions.

一旦 Q3Action 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.

特性文档编制

accel : QKeySequence

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.

访问函数:

QKeySequence accel () const
virtual void setAccel (const QKeySequence & key )

enabled : bool

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 Q3Action::whatsThis property is set.

访问函数:

bool isEnabled () const
virtual void setEnabled (bool)

iconSet : QIcon

此特性保持动作的图标。

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.

若 null 图标 ( QIcon::isNull () is passed into this function, the icon of the action is cleared.

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

访问函数:

QIcon iconSet () const
virtual void setIconSet (const QIcon &)

此特性保持动作的菜单文本。

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.

访问函数:

QString menuText () const
virtual void setMenuText (const QString &)

另请参阅 text .

on : bool

This property holds whether a toggle action is on.

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

访问函数:

bool isOn () const
virtual void setOn (bool)

另请参阅 toggleAction .

statusTip : QString

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.

访问函数:

QString statusTip () const
virtual void setStatusTip (const QString &)

另请参阅 setToolTip ().

text : QString

This property holds the action's descriptive text.

访问函数:

QString text () const
virtual void setText (const QString &)

另请参阅 setMenuText (), setToolTip (),和 setStatusTip ().

toggleAction : bool

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 Q3ActionGroup 采用 Q3ActionGroup::exclusive 特性被设为 true。

访问函数:

bool isToggleAction () const
virtual void setToggleAction (bool)

toolTip : QString

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.

访问函数:

QString toolTip () const
virtual void setToolTip (const QString &)

另请参阅 setStatusTip () 和 setAccel ().

visible : bool

This property holds whether the action can be seen (e.g. in menus and toolbars).

visible 为 true,动作可见 (如:在菜单和工具栏) 并由用户选取;若 visible 为 false,动作不可见 (或由用户选取)。

不可见动作 not 变灰;它们根本不出现。

访问函数:

bool isVisible () const
virtual void setVisible (bool)

whatsThis : QString

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.

访问函数:

QString whatsThis () const
virtual void setWhatsThis (const QString &)

另请参阅 QWhatsThis .

成员函数文档编制

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

构造动作称为 name 采用父级 parent .

parent Q3ActionGroup , 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.

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

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

This constructor results in an icon-less action with the menu text menuText and keyboard accelerator accel . It is a child of parent and called name .

parent Q3ActionGroup , 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.

动作使用剥离版本的 menuText (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 and accel will be used for tool tips and status tips unless you provide text for these using setToolTip () 和 setStatusTip ().

调用 setToggleAction (true) to make the action a toggle action.

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

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

This constructor creates an action with the following properties: the icon or icon icon , the menu text menuText and keyboard accelerator accel . It is a child of parent and called name .

parent Q3ActionGroup , 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.

动作使用剥离版本的 menuText (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 and accel will be used for tool tips and status tips unless you provide text for these using setToolTip () 和 setStatusTip ().

调用 setToggleAction (true) to make the action a toggle action.

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

Q3Action:: Q3Action (const QString & text , const QIcon & icon , const QString & menuText , QKeySequence accel , QObject * parent , const char * name = 0, bool toggle = false)

This constructor creates an action with the following properties: the description text , the icon or icon icon , the menu text menuText and keyboard accelerator accel . It is a child of parent and called name 。若 toggle is true the action will be a toggle action, otherwise it will be a command action.

parent Q3ActionGroup , 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 will be used for tool tips and status tips unless you provide specific text for these using setToolTip () 和 setStatusTip ().

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

This constructor results in an icon-less action with the description text , the menu text menuText and the keyboard accelerator accel . Its parent is parent and it is called name 。若 toggle is true the action will be a toggle action, otherwise it will be a command action.

The action automatically becomes a member of parent if parent Q3ActionGroup .

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 will be used for tool tips and status tips unless you provide specific text for these using setToolTip () 和 setStatusTip ().

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

构造动作称为 name 采用父级 parent .

toggle is true the action will be a toggle action, otherwise it will be a command action.

parent Q3ActionGroup , 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.

Q3Action:: ~Q3Action ()

销毁对象并释放分配的资源。

[slot] void Q3Action:: activate ()

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

另请参阅 toggle ().

[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 the toggled () signal for toggle actions.

[虚拟] bool Q3Action:: addTo ( QWidget * w )

Adds this action to widget w .

Currently actions may be added to Q3ToolBar and Q3PopupMenu 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. (If w is not a Q3ToolBar or Q3PopupMenu the action will not be added and false will be returned.)

另请参阅 removeFrom ().

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

此函数被调用从 addTo () function when it has created a widget ( actionWidget ) for the action in the container .

[virtual protected] void Q3Action:: addedTo ( int index , Q3PopupMenu * menu )

这是重载函数。

此函数被调用从 addTo () function when it has created a menu item at the index position index in the popup menu menu .

[虚拟] bool Q3Action:: removeFrom ( QWidget * w )

Removes the action from widget w .

Returns true if the action was removed successfully; otherwise returns false.

另请参阅 addTo ().

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

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

enabled 文档编制,了解更多信息。

[slot] void Q3Action:: toggle ()

Toggles the state of a toggle action.

另请参阅 on , activate (), toggled (),和 isToggleAction ().

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

This signal is emitted when a toggle action changes state; command actions and Q3ActionGroup s don't emit toggled().

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.

另请参阅 activated (), setToggleAction (),和 setOn ().