Eneboo - Documentación para desarrolladores
Slots públicos | Señales | Métodos públicos | Métodos protegidos | Propiedades | Amigas
Referencia de la Clase QAction

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

#include <qaction.h>

Diagrama de herencias de QAction
QObject QObject Qt Qt Qt Qt Action FLWidgetAction QActionGroup QActionGroup QDesignerAction QSeparatorAction ToolBarItem WidgetAction

Lista de todos los miembros.

Slots públicos

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

Señales

void activated ()
void toggled (bool)
void activated ()
void toggled (bool)

Métodos públicos

 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)
 QAction (const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name=0, bool toggle=FALSE)
 QAction (QObject *parent, const char *name, bool toggle)
 ~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 *)
virtual bool removeFrom (QWidget *)
 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)
 QAction (const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name=0, bool toggle=FALSE)
 QAction (QObject *parent, const char *name, bool toggle)
 ~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 *)
virtual bool removeFrom (QWidget *)

Métodos protegidos

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

Propiedades

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

Amigas

class QActionGroup
class QActionGroupPrivate

Descripción detallada

The QAction 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 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 QAction may contain an icon, a menu text, an accelerator, a status text, a whats 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() and 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() returns FALSE.

Actions are added to widgets (menus or toolbars) using addTo(), and removed using removeFrom().

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

action/application.cpp QPixmap( fileopen connect

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 is no menu or toolbar action, we'll add them next:

new QToolBar fileSaveAction->addTo new QPopupMenu insertItem fileSaveAction->addTo

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


Documentación del constructor y destructor

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.

Atención:
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 results in an icon-less action with the the menu text menuText and keyboard accelerator accel. It is a child of parent and 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 (e.g. "\&Menu Option..." becomes "Menu Option") as descriptive text for toolbuttons. 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() and setStatusTip().

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

Atención:
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 the following properties: the icon or iconset icon, the menu text menuText and keyboard accelerator accel. It is a child of parent and 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 (e.g. "\&Menu Option..." becomes "Menu Option") as descriptive text for toolbuttons. 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() and setStatusTip().

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

Atención:
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 constructor creates an action with the following properties: the description text, the icon or iconset icon, the menu text menuText and keyboard accelerator accel. It is a child of parent and called name. If toggle is TRUE the action will be a toggle action, otherwise it will 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 will be used for tool tips and status tips unless you provide specific text for these using setToolTip() and setStatusTip().

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

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

Constructs an action called name with parent parent.

If toggle is TRUE the action will be a toggle action, otherwise it will 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.

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

Documentación de las funciones miembro

QKeySequence QAction::accel ( ) const
QKeySequence QAction::accel ( ) const
void QAction::activate ( ) [slot]

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

Ver también:
toggle()
void QAction::activate ( ) [slot]
void QAction::activated ( ) [signal]

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.

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

This function is called from the addTo() function when it has created a widget (actionWidget) for the action in the container.

Reimplementado en FLWidgetAction, QActionGroup, QActionGroup, QDesignerActionGroup, QDesignerAction y WidgetAction.

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

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. 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.

Reimplementado en QActionGroup, QActionGroup, QDesignerActionGroup y QDesignerAction.

virtual void QAction::addedTo ( QWidget actionWidget,
QWidget container 
) [protected, virtual]
virtual void QAction::addedTo ( int  index,
QPopupMenu menu 
) [protected, virtual]
bool QAction::addTo ( QWidget w) [virtual]

Adds this action to widget w.

Currently actions may be added to QToolBar and QPopupMenu 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 QToolBar or QPopupMenu the action will not be added and FALSE will be returned.)

Ver también:
removeFrom()

Reimplementado en QActionGroup, QActionGroup, QDesignerAction y QSeparatorAction.

virtual bool QAction::addTo ( QWidget ) [virtual]
QIconSet QAction::iconSet ( ) const
QIconSet QAction::iconSet ( ) const
bool QAction::isEnabled ( ) const
bool QAction::isEnabled ( ) const
bool QAction::isOn ( ) const
bool QAction::isOn ( ) const
bool QAction::isToggleAction ( ) const
bool QAction::isToggleAction ( ) const
bool QAction::isVisible ( ) const
bool QAction::isVisible ( ) const
QString QAction::menuText ( ) const
QString QAction::menuText ( ) const
bool QAction::removeFrom ( QWidget w) [virtual]

Removes the action from widget w.

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

Ver también:
addTo()

Reimplementado en QActionGroup, QActionGroup, QDesignerAction y QSeparatorAction.

virtual bool QAction::removeFrom ( QWidget ) [virtual]
virtual void QAction::setAccel ( const QKeySequence key) [virtual]
void QAction::setAccel ( const QKeySequence key) [virtual]
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::setDisabled ( bool  ) [slot]
void QAction::setEnabled ( bool  enable) [virtual, slot]

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

void QAction::setStatusTip ( const QString tip) [virtual]
virtual void QAction::setStatusTip ( const QString ) [virtual]
virtual void QAction::setText ( const QString ) [virtual]

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

void QAction::setToggleAction ( bool  enable) [virtual]

Reimplementado en QActionGroup y QActionGroup.

virtual void QAction::setToggleAction ( bool  ) [virtual]

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

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

Reimplementado en QActionGroup y QActionGroup.

void QAction::setVisible ( bool  visible) [slot]
void QAction::setVisible ( bool  ) [slot]
virtual void QAction::setWhatsThis ( const QString ) [virtual]

Reimplementado en QActionGroup, QActionGroup y Action.

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

Reimplementado en QActionGroup, QActionGroup y Action.

QString QAction::statusTip ( ) const
QString QAction::statusTip ( ) const
QString QAction::text ( ) const
QString QAction::text ( ) const
void QAction::toggle ( ) [slot]

Toggles the state of a toggle action.

Ver también:
on, activate(), toggled(), isToggleAction()
void QAction::toggle ( ) [slot]
void QAction::toggled ( bool  ) [signal]
void QAction::toggled ( bool  on) [signal]

This signal is emitted when a toggle action changes state; command actions and {QActionGroup}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, e.g.

action/toggleaction/toggleaction.cpp QMainWindow * window QMainWindow * window labelonoffaction labelonoffaction connect setUsesTextLabel

Ver también:
activated() setToggleAction() setOn()
QString QAction::toolTip ( ) const
QString QAction::toolTip ( ) const
QString QAction::whatsThis ( ) const
QString QAction::whatsThis ( ) const

Documentación de las funciones relacionadas y clases amigas

QActionGroup [friend]

Documentación de propiedades

QKeySequence QAction::accel [read, write]

the action's accelerator key

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

bool QAction::enabled [read, write]

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.

QIconSet QAction::iconSet [read, write]

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

QString QAction::menuText [read, write]

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.

Ver también:
text
bool QAction::on [read, write]

whether a toggle action is on

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

Ver también:
toggleAction
QString QAction::statusTip [read, write]

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.

Ver también:
setStatusTip() setToolTip()
QString QAction::text [read, write]

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.

Ver también:
setMenuText() setToolTip() setStatusTip()
bool QAction::toggleAction [read, write]

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.

QString QAction::toolTip [read, write]

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.

Ver también:
setStatusTip() setAccel()
bool QAction::visible [read, write]

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.

QString QAction::whatsThis [read, write]

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.

Ver también:
QWhatsThis

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'