Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Q3Action Class Reference

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

 #include <Q3Action>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

Inherits: QObject.

Inherited by: Q3ActionGroup.

Properties

  • 1 property inherited from QObject

Public Functions

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
  • 29 public functions inherited from QObject

Public Slots

void activate ()
void setDisabled ( bool disable )
virtual void setEnabled ( bool )
virtual void setOn ( bool )
virtual void setVisible ( bool )
void toggle ()
  • 1 public slot inherited from QObject

Signals

void activated ()
void toggled ( bool on )

Protected Functions

virtual void addedTo ( QWidget * actionWidget, QWidget * container )
virtual void addedTo ( int index, Q3PopupMenu * menu )
  • 7 protected functions inherited from QObject

Additional Inherited Members

  • 5 static public members inherited from QObject

Detailed Description

The Q3Action 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 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() 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(). Note that when using Q3ToolBar and Q3PopupMenu, their actions must be Q3Actions.

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

Property Documentation

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.

Access functions:

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.

Access functions:

bool isEnabled () const
virtual void setEnabled ( bool )

iconSet : QIcon

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

menuText : QString

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

on : bool

This property holds whether a toggle action is on.

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

Access functions:

bool isOn () const
virtual void setOn ( bool )

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

Access functions:

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

See also setToolTip().

text : QString

This property holds the action's descriptive text.

Access functions:

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

See also setMenuText(), setToolTip(), and 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 with the Q3ActionGroup::exclusive property set to true.

Access functions:

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.

Access functions:

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

See also setStatusTip() and setAccel().

visible : bool

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.

Access functions:

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.

Access functions:

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

See also QWhatsThis.

Member Function Documentation

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

Constructs an action called name with parent parent.

If parent is a 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.

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

If parent is a 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 action uses a stripped version of 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() 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.

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.

If parent is a 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 action uses a stripped version of 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() 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.

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

If parent is a 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() and 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. 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 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() and setStatusTip().

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

Destroys the object and frees allocated resources.

void Q3Action::activate () [slot]

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

See also toggle().

void Q3Action::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.

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

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

See also removeFrom().

void Q3Action::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.

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

This is an overloaded 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.

bool Q3Action::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 Q3Action::setDisabled ( bool disable ) [slot]

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

See the enabled documentation for more information.

void Q3Action::toggle () [slot]

Toggles the state of a toggle action.

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

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

This signal is emitted when a toggle action changes state; command actions and Q3ActionGroups 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.

See also activated(), setToggleAction(), and setOn().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 53
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 82
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 28
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 229
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le Qt Labs au hasard

Logo

Améliorer les performances de Qt avec les chaînes de caractères avec SIMD... ou pas

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web