Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QAction Class Reference

Inheritance diagram for QAction:


List of all members.

Detailed Description

The QAction class provides an abstract user interface action that can be inserted into widgets.

parent and widget are different parent does not define context

In applications many common commands can be invoked via menus, toolbar buttons, and keyboard shortcuts. Since the user expects each command to be performed in the same way, regardless of the user interface used, it is useful to represent each command as an action.

Actions can be added to menus and toolbars, and will automatically keep them in sync. For example, in a word processor, if the user presses a Bold toolbar button, the Bold menu item will automatically be checked.

Actions can be created as independent objects, but they may also be created during the construction of menus; the QMenu class contains convenience functions for creating actions suitable for use as menu items.

A QAction may contain an icon, menu text, a shortcut, status text, "What's This?" text, and a tooltip. Most of these can be set in the constructor. They can also be set independently with setIcon(), setText(), setIconText(), setShortcut(), setStatusTip(), setWhatsThis(), and setToolTip(). For menu items, it is possible to set an individual font with setFont().

Actions are added to widgets using QWidget::addAction().

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

mainwindows/application/mainwindow.cpp openAct connect fileMenu->addAction(openAct fileMenu->addAction(openAct fileToolBar->addAction(openAct fileToolBar->addAction(openAct

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

Definition at line 41 of file qaction.h.

Public Types

enum  ActionEvent { Trigger, Hover }

Public Slots

void deleteLater ()
void hover ()
void setChecked (bool)
void setDisabled (bool b)
void setEnabled (bool)
void setVisible (bool)
void toggle ()
void trigger ()


void changed ()
void destroyed (QObject *=0)
void hovered ()
void toggled (bool)
void triggered (bool checked=false)

Public Member Functions

QActionGroupactionGroup () const
void activate (ActionEvent event)
bool blockSignals (bool b)
const QObjectListchildren () const
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
QVariant data () const
bool disconnect (const QObject *receiver, const char *member=0)
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
void dumpObjectInfo ()
void dumpObjectTree ()
virtual bool eventFilter (QObject *, QEvent *)
template<typename T>
findChild (const QString &name=QString()) const
template<typename T>
QList< T > findChildren (const QRegExp &re) const
template<typename T>
QList< T > findChildren (const QString &name=QString()) const
QFont font () const
QIcon icon () const
QString iconText () const
bool inherits (const char *classname) const
void installEventFilter (QObject *)
bool isCheckable () const
bool isChecked () const
bool isEnabled () const
bool isSeparator () const
bool isVisible () const
bool isWidgetType () const
void killTimer (int id)
QMenumenu () const
void moveToThread (QThread *thread)
QString objectName () const
QObjectparent () const
QWidgetparentWidget () const
QVariant property (const char *name) const
 QAction (const QIcon &icon, const QString &text, QObject *parent)
 QAction (const QString &text, QObject *parent)
 QAction (QObject *parent)
void removeEventFilter (QObject *)
void setActionGroup (QActionGroup *group)
void setCheckable (bool)
void setData (const QVariant &var)
void setFont (const QFont &font)
void setIcon (const QIcon &icon)
void setIconText (const QString &text)
void setMenu (QMenu *menu)
void setObjectName (const QString &name)
void setParent (QObject *)
bool setProperty (const char *name, const QVariant &value)
void setSeparator (bool b)
void setShortcut (const QKeySequence &shortcut)
void setShortcutContext (Qt::ShortcutContext context)
void setStatusTip (const QString &statusTip)
void setText (const QString &text)
void setToolTip (const QString &tip)
void setUserData (uint id, QObjectUserData *data)
void setWhatsThis (const QString &what)
QKeySequence shortcut () const
Qt::ShortcutContext shortcutContext () const
bool showStatusText (QWidget *widget=0)
bool signalsBlocked () const
int startTimer (int interval)
QString statusTip () const
QString text () const
QThreadthread () const
QString toolTip () const
QObjectUserData * userData (uint id) const
QString whatsThis () const
 ~QAction ()

Static Public Member Functions

static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
static uint registerUserData ()

Protected Member Functions

virtual void childEvent (QChildEvent *)
virtual void connectNotify (const char *signal)
virtual void customEvent (QEvent *)
virtual void disconnectNotify (const char *signal)
bool event (QEvent *)
int receivers (const char *signal) const
QObjectsender () const
virtual void timerEvent (QTimerEvent *)

Protected Attributes

QObjectData * d_ptr

Static Protected Attributes

static const QMetaObject staticQtMetaObject


bool checkable
 whether the action is a checkable action
bool checked
 whether the action is checked.
bool enabled
 whether the action is enabled
QFont font
 the action's font
QIcon icon
 the action's icon
QString iconText
 the action's descriptive icon text
QString objectName
 the name of this object
QKeySequence shortcut
 the action's shortcut key
Qt::ShortcutContext shortcutContext
 the context for the action's shortcut
QString statusTip
 the action's status tip
QString text
 the action's descriptive text
QString toolTip
 the action's tooltip
bool visible
 whether the action can be seen (e.g. in menus and toolbars)
QString whatsThis
 the action's "What's This?" help text


class QActionGroup
class QApplication
class QApplicationPrivate
class QCoreApplication
class QCoreApplicationPrivate
class QMenu
class QMenuBar
struct QMetaObject
class QShortcutMap
class QThreadData
class QWidget

Related Functions

(Note that these are not member functions.)

qFindChild (const QObject *obj, const QString &name)
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
QList< T > qFindChildren (const QObject *obj, const QString &name)
T * qobject_cast (QObject *object)
void * qt_find_obj_child (QObject *parent, const char *type, const QString &name)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index