QAction Class Reference

#include <qaction.h>

Inheritance diagram for QAction:

Inheritance graph
[legend]
Collaboration diagram for QAction:

Collaboration graph
[legend]
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.

See also:
QMenu, QToolBar, {Application Example}

Definition at line 43 of file qaction.h.

Public Types

enum  MenuRole
enum  ActionEvent

Public Slots

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

Signals

void changed ()
void triggered (bool checked=false)
void hovered ()
void toggled (bool)

Public Member Functions

 QAction (QObject *parent)
 QAction (const QString &text, QObject *parent)
 QAction (const QIcon &icon, const QString &text, QObject *parent)
 ~QAction ()
void setActionGroup (QActionGroup *group)
QActionGroupactionGroup () const
void setIcon (const QIcon &icon)
QIcon icon () const
void setText (const QString &text)
QString text () const
void setIconText (const QString &text)
QString iconText () const
void setToolTip (const QString &tip)
QString toolTip () const
void setStatusTip (const QString &statusTip)
QString statusTip () const
void setWhatsThis (const QString &what)
QString whatsThis () const
QMenumenu () const
void setMenu (QMenu *menu)
void setSeparator (bool b)
bool isSeparator () const
void setShortcut (const QKeySequence &shortcut)
QKeySequence shortcut () const
void setShortcuts (const QList< QKeySequence > &shortcuts)
void setShortcuts (QKeySequence::StandardKey)
QList< QKeySequenceshortcuts () const
void setShortcutContext (Qt::ShortcutContext context)
Qt::ShortcutContext shortcutContext () const
void setAutoRepeat (bool)
bool autoRepeat () const
void setFont (const QFont &font)
QFont font () const
void setCheckable (bool)
bool isCheckable () const
QVariant data () const
void setData (const QVariant &var)
bool isChecked () const
bool isEnabled () const
bool isVisible () const
void activate (ActionEvent event)
bool showStatusText (QWidget *widget=0)
void setMenuRole (MenuRole menuRole)
MenuRole menuRole () const
QWidgetparentWidget () const
QList< QWidget * > associatedWidgets () const

Protected Member Functions

bool event (QEvent *)
 QAction (QActionPrivate &dd, QObject *parent)

Friends

class QWidget
class QActionGroup
class QMenu
class QMenuBar
class QShortcutMap
class QToolButton


Member Enumeration Documentation

enum QAction::MenuRole

This enum describes how an action should be moved into the application menu on Mac OS X.

NoRole This action should not be put into the application menu TextHeuristicRole This action should be put in the application menu based on the action's text as described in the QMenuBar documentation. ApplicationSpecificRole This action should be put in the application menu with an application specific role AboutQtRole This action matches handles the "About Qt" menu item. AboutRole This action should be placed where the "About" menu item is in the application menu. PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu. QuitRole This action should be placed where the Quit menu item is in the application menu.

Definition at line 68 of file qaction.h.

enum QAction::ActionEvent

This enum type is used when calling QAction::activate()

Trigger this will cause the QAction::triggered() signal to be emitted.

Hover this will cause the QAction::hovered() signal to be emitted.

Definition at line 142 of file qaction.h.

00142 { Trigger, Hover };


Constructor & Destructor Documentation

QAction::QAction ( QObject parent  )  [explicit]

Constructs an action with parent. If parent is an action group the action will be automatically inserted into the group.

Definition at line 227 of file qaction.cpp.

References d, and QObject::parent().

00228     : QObject(*(new QActionPrivate), parent)
00229 {
00230     Q_D(QAction);
00231     d->group = qobject_cast<QActionGroup *>(parent);
00232     if (d->group)
00233         d->group->addAction(this);
00234 }

Here is the call graph for this function:

QAction::QAction ( const QString text,
QObject parent 
)

Constructs an action with some text and parent. If parent is an action group the action will be automatically inserted into the group.

The action uses a stripped version of text (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 will be used for tooltips unless you specify a different test using setToolTip().

Definition at line 250 of file qaction.cpp.

References d, QObject::parent(), and text().

00251     : QObject(*(new QActionPrivate), parent)
00252 {
00253     Q_D(QAction);
00254     d->text = text;
00255     d->group = qobject_cast<QActionGroup *>(parent);
00256     if (d->group)
00257         d->group->addAction(this);
00258 }

Here is the call graph for this function:

QAction::QAction ( const QIcon icon,
const QString text,
QObject parent 
)

Constructs an action with an icon and some text and parent. If parent is an action group the action will be automatically inserted into the group.

The action uses a stripped version of text (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 will be used for tooltips unless you specify a different test using setToolTip().

Definition at line 272 of file qaction.cpp.

References d, icon(), QObject::parent(), and text().

00273     : QObject(*(new QActionPrivate), parent)
00274 {
00275     Q_D(QAction);
00276     d->icon = icon;
00277     d->text = text;
00278     d->group = qobject_cast<QActionGroup *>(parent);
00279     if (d->group)
00280         d->group->addAction(this);
00281 }

Here is the call graph for this function:

QAction::~QAction (  ) 

Destroys the object and frees allocated resources.

Definition at line 544 of file qaction.cpp.

References d, i, qApp, and w.

00545 {
00546     Q_D(QAction);
00547     for (int i = d->widgets.size()-1; i >= 0; --i) {
00548         QWidget *w = d->widgets.at(i);
00549         w->removeAction(this);
00550     }
00551     if (d->group)
00552         d->group->removeAction(this);
00553 #ifndef QT_NO_SHORTCUT
00554     if (d->shortcutId && qApp)
00555         qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this);
00556 #endif
00557 }

QAction::QAction ( QActionPrivate dd,
QObject parent 
) [protected]

Definition at line 286 of file qaction.cpp.

References d, and QObject::parent().

00287     : QObject(dd, parent)
00288 {
00289     Q_D(QAction);
00290     d->group = qobject_cast<QActionGroup *>(parent);
00291     if (d->group)
00292         d->group->addAction(this);
00293 }

Here is the call graph for this function:


Member Function Documentation

void QAction::setActionGroup ( QActionGroup group  ) 

Sets this action group to group. The action will be automatically added to the group's list of actions.

Actions within the group will be mutually exclusive.

See also:
QActionGroup, QAction::actionGroup()

Definition at line 567 of file qaction.cpp.

References QActionGroup::addAction(), and d.

Referenced by QToolBar::resizeEvent().

00568 {
00569     Q_D(QAction);
00570     if(group == d->group)
00571         return;
00572 
00573     if(d->group)
00574         d->group->removeAction(this);
00575     d->group = group;
00576     if(group)
00577         group->addAction(this);
00578 }

Here is the call graph for this function:

QActionGroup * QAction::actionGroup (  )  const

Returns the action group for this action. If no action group manages this action then 0 will be returned.

See also:
QActionGroup, QAction::setActionGroup()

Definition at line 586 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::getStyleOption().

00587 {
00588     Q_D(const QAction);
00589     return d->group;
00590 }

void QAction::setIcon ( const QIcon icon  ) 

Definition at line 604 of file qaction.cpp.

References d, and icon().

Referenced by QWorkspacePrivate::_q_updateActions(), qdesigner_internal::ActionEditor::ActionEditor(), Q3ActionGroup::addTo(), QDesignerFormWindow::changeEvent(), QDesignerToolWindow::changeEvent(), TextEdit::colorChanged(), qdesigner_internal::createCheckableAction(), qdesigner_internal::SignalSlotEditorPlugin::initialize(), qdesigner_internal::BuddyEditorPlugin::initialize(), qdesigner_internal::TabOrderEditorPlugin::initialize(), QDesignerActions::QDesignerActions(), QWhatsThisAction::QWhatsThisAction(), MainWindow::setActionsEnabled(), QtWindowListMenu::setCascadeIcon(), QtWindowListMenu::setCloseAllIcon(), QtWindowListMenu::setCloseIcon(), QtWindowListMenu::setTileIcon(), MainWindow::setupGoActions(), and SpreadSheet::updateColor().

00605 {
00606     Q_D(QAction);
00607     d->icon = icon;
00608     d->sendDataChanged();
00609 }

Here is the call graph for this function:

QIcon QAction::icon (  )  const

Definition at line 611 of file qaction.cpp.

References d.

Referenced by qdesigner_internal::ActionEditor::createListWidgetItem(), qdesigner_internal::ActionEditor::editAction(), QMenuBarPrivate::getStyleOption(), QMenuPrivate::getStyleOption(), QDesignerWorkbench::initialize(), qdesigner_internal::ActionEditor::manageAction(), QAction(), setIcon(), qdesigner_internal::ActionEditor::slotActionChanged(), QDesignerMenuBar::startDrag(), QDesignerMenu::startDrag(), and QDesignerToolBar::startDrag().

00612 {
00613     Q_D(const QAction);
00614     return d->icon;
00615 }

void QAction::setText ( const QString text  ) 

Definition at line 685 of file qaction.cpp.

References d, and text().

Referenced by QWorkspacePrivate::_q_updateActions(), Q3ActionGroup::addTo(), qdesigner_internal::ButtonTaskMenu::ButtonTaskMenu(), QDesignerFormWindow::changeEvent(), QDesignerToolWindow::changeEvent(), qdesigner_internal::ComboBoxTaskMenu::ComboBoxTaskMenu(), qdesigner_internal::createCheckableAction(), QDockWidgetPrivate::init(), HelpDialog::initialize(), qdesigner_internal::LabelTaskMenu::LabelTaskMenu(), qdesigner_internal::LineEditTaskMenu::LineEditTaskMenu(), qdesigner_internal::ListWidgetTaskMenu::ListWidgetTaskMenu(), QDesignerMenuBar::QDesignerMenuBar(), QDesignerTabWidget::QDesignerTabWidget(), QDesignerToolBox::QDesignerToolBox(), QDesignerToolWindow::QDesignerToolWindow(), MainWindow::setActionsEnabled(), QUndoAction::setPrefixedText(), MainWindow::setup(), MainWindow::setupGoActions(), qdesigner_internal::TableWidgetTaskMenu::TableWidgetTaskMenu(), qdesigner_internal::TextEditTaskMenu::TextEditTaskMenu(), ToolBar::ToolBar(), qdesigner_internal::ToolBarTaskMenu::ToolBarTaskMenu(), qdesigner_internal::TreeWidgetTaskMenu::TreeWidgetTaskMenu(), and MainWindow::updateRecentFileActions().

00686 {
00687     Q_D(QAction);
00688     if (d->text == text)
00689         return;
00690 
00691     d->text = text;
00692     d->sendDataChanged();
00693 }

Here is the call graph for this function:

QString QAction::text (  )  const

Definition at line 695 of file qaction.cpp.

References d, and s.

Referenced by QCalendarWidgetPrivate::_q_monthChanged(), MainWindow::actionTriggered(), MainWindow::applyFilter(), MainWindow::changeBrush(), QDesignerFormWindow::closeEvent(), QDesignerMenu::createRealMenuAction(), qdesigner_internal::ActionEditor::editAction(), QMenuBarPrivate::getStyleOption(), QMenuPrivate::getStyleOption(), QDesignerWorkbench::initialize(), MainWindow::insertShape(), QMenu::keyPressEvent(), Q3TextEdit::pickSpecial(), QAction(), TrWindow::recentFileActivated(), setIconText(), QUndoAction::setPrefixedText(), setText(), QDesignerMenu::showLineEdit(), QDesignerMenuBar::showLineEdit(), ColorSwatch::splitInto(), ColorSwatch::tabInto(), and QMenuBarPrivate::updateGeometries().

00696 {
00697     Q_D(const QAction);
00698     QString s = d->text;
00699     if(s.isEmpty()) {
00700         s = d->iconText;
00701         s.replace(QLatin1Char('&'), QLatin1String("&&"));
00702     }
00703     return s;
00704 }

void QAction::setIconText ( const QString text  ) 

Definition at line 729 of file qaction.cpp.

References d, and text().

00730 {
00731     Q_D(QAction);
00732     if (d->iconText == text)
00733         return;
00734 
00735     d->iconText = text;
00736     d->sendDataChanged();
00737 }

Here is the call graph for this function:

QString QAction::iconText (  )  const

Definition at line 739 of file qaction.cpp.

References d, and qt_strippedText().

00740 {
00741     Q_D(const QAction);
00742     if (d->iconText.isEmpty())
00743         return qt_strippedText(d->text);
00744     return d->iconText;
00745 }

Here is the call graph for this function:

void QAction::setToolTip ( const QString tip  ) 

Definition at line 758 of file qaction.cpp.

References d.

00759 {
00760     Q_D(QAction);
00761     if (d->tooltip == tooltip)
00762         return;
00763 
00764     d->tooltip = tooltip;
00765     d->sendDataChanged();
00766 }

QString QAction::toolTip (  )  const

Definition at line 768 of file qaction.cpp.

References d, and qt_strippedText().

00769 {
00770     Q_D(const QAction);
00771     if (d->tooltip.isEmpty()) {
00772         if (!d->text.isEmpty())
00773             return qt_strippedText(d->text);
00774         return d->iconText;
00775     }
00776     return d->tooltip;
00777 }

Here is the call graph for this function:

void QAction::setStatusTip ( const QString statusTip  ) 

Definition at line 788 of file qaction.cpp.

References d.

Referenced by qdesigner_internal::FormWindowManager::setupActions().

00789 {
00790     Q_D(QAction);
00791     if (d->statustip == statustip)
00792         return;
00793 
00794     d->statustip = statustip;
00795     d->sendDataChanged();
00796 }

QString QAction::statusTip (  )  const

Definition at line 798 of file qaction.cpp.

References d.

Referenced by showStatusText().

00799 {
00800     Q_D(const QAction);
00801     return d->statustip;
00802 }

void QAction::setWhatsThis ( const QString what  ) 

Definition at line 814 of file qaction.cpp.

References d.

Referenced by qdesigner_internal::FormWindowManager::setupActions(), and MainWindow::setupGoActions().

00815 {
00816     Q_D(QAction);
00817     if (d->whatsthis == whatsthis)
00818         return;
00819 
00820     d->whatsthis = whatsthis;
00821     d->sendDataChanged();
00822 }

QString QAction::whatsThis (  )  const

Definition at line 824 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::activateAction(), and QAccessibleMenu::text().

00825 {
00826     Q_D(const QAction);
00827     return d->whatsthis;
00828 }

QMenu * QAction::menu (  )  const

Returns the menu contained by this action. Actions that contain menus can be used to create menu items with submenus, or inserted into toolbars to create buttons with popup menus.

See also:
QMenu::addAction()

Definition at line 625 of file qaction.cpp.

References d.

Referenced by Q3ActionGroup::addTo(), QDesignerMenuBar::adjustIndicator(), QDesignerMenuBar::checkAction(), QDesignerMenu::checkAction(), QAbstractFormBuilder::createActionRefDom(), qdesigner_internal::QDesignerResource::createDom(), QAbstractFormBuilder::createDom(), qdesigner_internal::ActionEditor::createListWidgetItem(), QDesignerMenu::createRealMenuAction(), QAccessibleMenu::doAction(), QAccessibleMenuBar::doAction(), QDesignerMenu::dropEvent(), QDesignerMenu::enterEditMode(), QDesignerMenu::findOrCreateSubMenu(), QMenuPrivate::getStyleOption(), QDesignerMenu::handleMouseMoveEvent(), QDesignerMenu::handleMousePressEvent(), QToolButtonPrivate::hasMenu(), QDesignerMenu::hasSubMenuPixmap(), QDesignerMenuBar::hideMenu(), qdesigner_internal::RemoveMenuActionCommand::init(), qdesigner_internal::AddMenuActionCommand::init(), QMenu::keyPressEvent(), QDesignerMenu::leaveEditMode(), qdesigner_internal::ActionEditor::manageAction(), qdesigner_internal::merge(), QMenu::mouseReleaseEvent(), QMenuBar::mouseReleaseEvent(), QDesignerMenuBar::paintEvent(), QMenuBarPrivate::popupAction(), QMenuPrivate::popupAction(), QToolButtonPrivate::popupTimerDone(), qdesigner_internal::AddMenuActionCommand::redo(), qdesigner_internal::RemoveMenuActionCommand::redo(), QDesignerMenu::removeRealMenu(), QMenuPrivate::setCurrentAction(), qdesigner_internal::ObjectInspector::setFormWindow(), setMenu(), QDesignerMenuBar::showMenu(), qdesigner_internal::ActionEditor::slotActionChanged(), qdesigner_internal::AddMenuActionCommand::undo(), qdesigner_internal::RemoveMenuActionCommand::undo(), and qdesigner_internal::ActionEditor::updatePropertyEditor().

00626 {
00627     Q_D(const QAction);
00628     return d->menu;
00629 }

void QAction::setMenu ( QMenu menu  ) 

Sets the menu contained by this action to the specified menu.

Definition at line 634 of file qaction.cpp.

References d, and menu().

Referenced by Window::createPushButtonGroup(), QDesignerMenu::createRealMenuAction(), and QDesignerMenu::removeRealMenu().

00635 {
00636     Q_D(QAction);
00637     d->menu = menu;
00638     d->sendDataChanged();
00639 }

Here is the call graph for this function:

void QAction::setSeparator ( bool  b  ) 

If b is true then this action will be considered a separator.

How a separator is represented depends on the widget it is inserted into. Under most circumstances the text, submenu, and icon will be ignored for separator actions.

See also:
QAction::isSeparator()

Definition at line 651 of file qaction.cpp.

References d.

Referenced by QMenuBar::addSeparator(), QToolBar::addSeparator(), QMenu::addSeparator(), Q3Action::addTo(), qdesigner_internal::ButtonTaskMenu::ButtonTaskMenu(), qdesigner_internal::ComboBoxTaskMenu::ComboBoxTaskMenu(), qdesigner_internal::ContainerWidgetTaskMenu::ContainerWidgetTaskMenu(), QAbstractFormBuilder::create(), qdesigner_internal::QDesignerResource::create(), QDesignerMenu::createAction(), QDesignerToolBar::createAction(), SpreadSheet::createActions(), qdesigner_internal::FormWindow::finishContextMenu(), qdesigner_internal::GroupBoxTaskMenu::GroupBoxTaskMenu(), QMenu::insertSeparator(), QMenuBar::insertSeparator(), QToolBar::insertSeparator(), qdesigner_internal::LabelTaskMenu::LabelTaskMenu(), qdesigner_internal::LineEditTaskMenu::LineEditTaskMenu(), qdesigner_internal::ListWidgetTaskMenu::ListWidgetTaskMenu(), QDesignerActions::QDesignerActions(), qdesigner_internal::QDesignerTaskMenu::QDesignerTaskMenu(), QMultiInputContext::QMultiInputContext(), qdesigner_internal::SentinelAction::SentinelAction(), qdesigner_internal::TableWidgetTaskMenu::TableWidgetTaskMenu(), qdesigner_internal::TextEditTaskMenu::TextEditTaskMenu(), qdesigner_internal::ToolBarTaskMenu::ToolBarTaskMenu(), and qdesigner_internal::TreeWidgetTaskMenu::TreeWidgetTaskMenu().

00652 {
00653     Q_D(QAction);
00654     if (d->separator == b)
00655         return;
00656 
00657     d->separator = b;
00658     d->sendDataChanged();
00659 }

bool QAction::isSeparator (  )  const

Returns true if this action is a separator action; otherwise it returns false.

See also:
QAction::setSeparator()

Definition at line 667 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::activateAction(), QDesignerWorkbench::changeBringToFrontVisiblity(), QAccessibleMenu::childAt(), QAbstractFormBuilder::createActionRefDom(), QAbstractFormBuilder::createDom(), QToolBarPrivate::createItem(), QMenuPrivate::filterActions(), QMenuPrivate::getStyleOption(), QDesignerMenu::hasSubMenuPixmap(), qdesigner_internal::ActionEditor::manageAction(), QAccessibleMenuBar::role(), QAccessibleMenu::role(), QMenuPrivate::setCurrentAction(), qdesigner_internal::ActionEditor::setFormWindow(), QDesignerMenu::showLineEdit(), QDesignerMenuBar::showLineEdit(), QDesignerMenu::showSubMenu(), QDesignerMenu::slotShowSubMenuNow(), QAccessibleMenu::state(), and QAccessibleMenuBar::state().

00668 {
00669     Q_D(const QAction);
00670     return d->separator;
00671 }

void QAction::setShortcut ( const QKeySequence shortcut  ) 

Definition at line 326 of file qaction.cpp.

References d, qApp, and shortcut().

Referenced by QMenu::addAction(), ColorSwatch::ColorSwatch(), QPixelTool::contextMenuEvent(), ImageViewer::createActions(), MainWindow::createActions(), SpreadSheet::createActions(), qdesigner_internal::SignalSlotEditorPlugin::initialize(), Launcher::Launcher(), QDBusViewer::QDBusViewer(), QDesignerActions::QDesignerActions(), QDesignerPropertyEditor::QDesignerPropertyEditor(), QWhatsThisAction::QWhatsThisAction(), qdesigner_internal::RichTextEditorToolBar::RichTextEditorToolBar(), qdesigner_internal::FormWindowManager::setupActions(), MainWindow::setupMenus(), TextEdit::setupTextActions(), and SourceTextEdit::SourceTextEdit().

00327 {
00328     Q_D(QAction);
00329     if (d->shortcut == shortcut)
00330         return;
00331 
00332     d->shortcut = shortcut;
00333     d->redoGrab(qApp->d_func()->shortcutMap);
00334     d->sendDataChanged();
00335 }

Here is the call graph for this function:

QKeySequence QAction::shortcut (  )  const

Returns the primary shortcut.

See also:
setShortcuts()

Definition at line 386 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::getStyleOption(), setShortcut(), and QAccessibleMenu::text().

00387 {
00388     Q_D(const QAction);
00389     return d->shortcut;
00390 }

void QAction::setShortcuts ( const QList< QKeySequence > &  shortcuts  ) 

Since:
4.2
Sets shortcuts as the list of shortcuts that trigger the action. The first element of the list is the primary shortcut.

See also:
shortcut

Definition at line 345 of file qaction.cpp.

References d, QList< T >::isEmpty(), qApp, shortcuts(), and QList< T >::takeFirst().

Referenced by setShortcuts().

00346 {
00347     Q_D(QAction);
00348 
00349     QList <QKeySequence> listCopy = shortcuts;
00350 
00351     QKeySequence primary;
00352     if (!listCopy.isEmpty())
00353         primary = listCopy.takeFirst();
00354 
00355     if (d->shortcut == primary && d->alternateShortcuts == listCopy)
00356         return;
00357 
00358     d->shortcut = primary;
00359     d->alternateShortcuts = listCopy;
00360     d->redoGrab(qApp->d_func()->shortcutMap);
00361     d->redoGrabAlternate(qApp->d_func()->shortcutMap);
00362     d->sendDataChanged();
00363 }

Here is the call graph for this function:

void QAction::setShortcuts ( QKeySequence::StandardKey  key  ) 

Since:
4.2
Sets a platform dependent list of shortcuts based on the key. The result of calling this function will depend on the currently running platform. Note that more than one shortcut can assigned by this action. If only the primary shortcut is required, use setShortcut instead.

See also:
QKeySequence::keyBindings()

Definition at line 375 of file qaction.cpp.

References QKeySequence::keyBindings(), and setShortcuts().

00376 {
00377     QList <QKeySequence> list = QKeySequence::keyBindings(key);
00378     setShortcuts(list);
00379 }

Here is the call graph for this function:

QList< QKeySequence > QAction::shortcuts (  )  const

Since:
4.2
Returns the list of shortcuts, with the primary shortcut as the first element of the list.

See also:
setShortcuts()

Definition at line 400 of file qaction.cpp.

References d.

Referenced by setShortcuts().

00401 {
00402     Q_D(const QAction);
00403     QList <QKeySequence> shortcuts;
00404     if (!d->shortcut.isEmpty())
00405         shortcuts << d->shortcut;
00406     if (!d->alternateShortcuts.isEmpty())
00407         shortcuts << d->alternateShortcuts;
00408     return shortcuts;
00409 }

void QAction::setShortcutContext ( Qt::ShortcutContext  context  ) 

Definition at line 418 of file qaction.cpp.

References d, and qApp.

Referenced by QDesignerToolWindow::QDesignerToolWindow().

00419 {
00420     Q_D(QAction);
00421     if (d->shortcutContext == context)
00422         return;
00423     d->shortcutContext = context;
00424     d->redoGrab(qApp->d_func()->shortcutMap);
00425     d->redoGrabAlternate(qApp->d_func()->shortcutMap);
00426     d->sendDataChanged();
00427 }

Qt::ShortcutContext QAction::shortcutContext (  )  const

Definition at line 429 of file qaction.cpp.

References d.

00430 {
00431     Q_D(const QAction);
00432     return d->shortcutContext;
00433 }

void QAction::setAutoRepeat ( bool   ) 

Definition at line 445 of file qaction.cpp.

References d, and qApp.

00446 {
00447     Q_D(QAction);
00448     if (d->autorepeat == on)
00449         return;
00450     d->autorepeat = on;
00451     d->redoGrab(qApp->d_func()->shortcutMap);
00452     d->redoGrabAlternate(qApp->d_func()->shortcutMap);
00453     d->sendDataChanged();
00454 }

bool QAction::autoRepeat (  )  const

Definition at line 456 of file qaction.cpp.

References d.

00457 {
00458     Q_D(const QAction);
00459     return d->autorepeat;
00460 }

void QAction::setFont ( const QFont font  ) 

Definition at line 473 of file qaction.cpp.

References d, and font().

Referenced by QDesignerMenuBar::QDesignerMenuBar(), and TextEdit::setupTextActions().

00474 {
00475     Q_D(QAction);
00476     if (d->font == font)
00477         return;
00478 
00479     d->fontSet = true;
00480     d->font = font;
00481     d->sendDataChanged();
00482 }

Here is the call graph for this function:

QFont QAction::font (  )  const

Definition at line 484 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::getStyleOption(), and setFont().

00485 {
00486     Q_D(const QAction);
00487     return d->font;
00488 }

void QAction::setCheckable ( bool   ) 

Definition at line 850 of file qaction.cpp.

References d.

Referenced by addAction(), MainWindow::addToMenu(), ColorSwatch::ColorSwatch(), QPixelTool::contextMenuEvent(), ImageViewer::createActions(), qdesigner_internal::createCheckableAction(), MainWindow::createMenu(), QVFb::createViewMenu(), QDockWidgetPrivate::init(), QToolBarPrivate::init(), Q3MainWindow::menuAboutToShow(), QDesignerActions::QDesignerActions(), QDesignerFormWindow::QDesignerFormWindow(), QDesignerToolWindow::QDesignerToolWindow(), QWhatsThisAction::QWhatsThisAction(), QToolBar::resizeEvent(), QFileDialogPrivate::setupActions(), MainWindow::setupDockWidgets(), TextEdit::setupTextActions(), ToolBar::ToolBar(), and MainWindow::updateWindowMenu().

00851 {
00852     Q_D(QAction);
00853     if (d->checkable == b)
00854         return;
00855 
00856     d->checkable = b;
00857     d->checked = false;
00858     d->sendDataChanged();
00859 }

bool QAction::isCheckable (  )  const

Definition at line 861 of file qaction.cpp.

References d.

Referenced by QMenuPrivate::getStyleOption().

00862 {
00863     Q_D(const QAction);
00864     return d->checkable;
00865 }

QVariant QAction::data (  )  const

Returns the user data as set in QAction::setData.

See also:
setData()

Definition at line 1004 of file qaction.cpp.

References d.

Referenced by QCalendarWidgetPrivate::_q_monthChanged(), MainWindow::aboutToShowSaveAsMenu(), MainWindow::changeStyle(), MainWindow::checkCurrentStyle(), MainWindow::openRecentFile(), setData(), QDBusViewer::showContextMenu(), QDesignerToolBar::slotInsertSeparator(), QDesignerToolBar::slotRemoveSelectedAction(), QDesignerMenu::slotRemoveSelectedAction(), and QDesignerMenuBar::slotRemoveSelectedAction().

01005 {
01006     Q_D(const QAction);
01007     return d->userData;
01008 }

void QAction::setData ( const QVariant userData  ) 

Sets the action's internal data to the given userData.

See also:
data()

Definition at line 1018 of file qaction.cpp.

References d, and data().

Referenced by QCalendarWidgetPrivate::createHeader(), QDesignerToolBar::handleContextMenuEvent(), QDesignerMenuBar::handleContextMenuEvent(), QDBusViewer::QDBusViewer(), qdesigner_internal::SetPropertyCommand::redo(), QDBusViewer::showContextMenu(), qdesigner_internal::SetPropertyCommand::undo(), and MainWindow::updateRecentFileActions().

01019 {
01020     Q_D(QAction);
01021     d->userData = data;
01022     d->sendDataChanged();
01023 }

Here is the call graph for this function:

bool QAction::isChecked (  )  const

Definition at line 901 of file qaction.cpp.

References d.

Referenced by QActionGroupPrivate::_q_actionChanged(), QFileDialogPrivate::_q_showHidden(), QWhatsThisAction::actionTriggered(), MainWindow::addImage(), QPixelTool::contextMenuEvent(), ImageViewer::fitToWindow(), QMenuPrivate::getStyleOption(), ImageViewer::open(), MainWindow::setSettingsObject(), QAccessibleMenu::state(), TextEdit::textBold(), TextEdit::textItalic(), TextEdit::textUnderline(), QVFb::toggleCursor(), and ImageViewer::updateActions().

00902 {
00903     Q_D(const QAction);
00904     return d->checked;
00905 }

bool QAction::isEnabled (  )  const

Definition at line 942 of file qaction.cpp.

References d.

Referenced by QMenuBarPrivate::activateAction(), QMenuPrivate::activateAction(), QAccessibleMenu::doAction(), QAccessibleMenuBar::doAction(), QMenuBarPrivate::getStyleOption(), QMenuPrivate::getStyleOption(), QMenuBarPrivate::popupAction(), QMenuPrivate::popupAction(), QAccessibleMenu::state(), and QAccessibleMenuBar::state().

00943 {
00944     Q_D(const QAction);
00945     return d->enabled;
00946 }

bool QAction::isVisible (  )  const

Definition at line 970 of file qaction.cpp.

References d.

Referenced by QToolBar::actionEvent(), and QMenuPrivate::filterActions().

00971 {
00972     Q_D(const QAction);
00973     return d->visible;
00974 }

void QAction::activate ( ActionEvent  event  ) 

Sends the relevant signals for ActionEvent event.

Action based widgets use this API to cause the QAction to emit signals as well as emitting their own.

Definition at line 1054 of file qaction.cpp.

References QMetaObject::addGuard(), d, emit, Hover, hovered(), QMetaObject::removeGuard(), setChecked(), and triggered().

Referenced by QMenuBarPrivate::activateAction(), QMenuPrivate::activateAction(), and event().

01055 {
01056     Q_D(QAction);
01057     if(event == Trigger) {
01058         QObject *guard = this;
01059         QMetaObject::addGuard(&guard);
01060         if(d->checkable) {
01061             // the checked action of an exclusive group cannot be  unchecked
01062             if (d->checked && (d->group && d->group->isExclusive()
01063                                && d->group->checkedAction() == this)) {
01064                 QMetaObject::removeGuard(&guard);
01065                 return;
01066             }
01067             setChecked(!d->checked);
01068         }
01069         if (guard)
01070             emit triggered(d->checked);
01071 #ifdef QT3_SUPPORT
01072         if (guard)
01073             emit activated(d->param);
01074 #endif
01075         QMetaObject::removeGuard(&guard);
01076     } else if(event == Hover) {
01077         emit hovered();
01078     }
01079 }

Here is the call graph for this function:

bool QAction::showStatusText ( QWidget widget = 0  ) 

Updates the status bar for widget. If widget is an appropriate QStatusBar found for for this action based on the parent heirarchy will be used.

See also:
statusTip

Definition at line 1034 of file qaction.cpp.

References object, QObject::parent(), QCoreApplication::sendEvent(), and statusTip().

Referenced by QMenuBarPrivate::activateAction(), and QMenuPrivate::activateAction().

01035 {
01036 #ifdef QT_NO_STATUSTIP
01037     Q_UNUSED(widget);
01038 #else
01039     if(QObject *object = widget ? widget : parent()) {
01040         QStatusTipEvent tip(statusTip());
01041         QApplication::sendEvent(object, &tip);
01042         return true;
01043     }
01044 #endif
01045     return false;
01046 }

Here is the call graph for this function:

void QAction::setMenuRole ( MenuRole  menuRole  ) 

Definition at line 1244 of file qaction.cpp.

References d.

Referenced by QDesignerActions::QDesignerActions().

01245 {
01246     Q_D(QAction);
01247     if (d->menuRole == menuRole)
01248         return;
01249 
01250     d->menuRole = menuRole;
01251     d->sendDataChanged();
01252 }

QAction::MenuRole QAction::menuRole (  )  const

Definition at line 1254 of file qaction.cpp.

References d.

01255 {
01256     Q_D(const QAction);
01257     return d->menuRole;
01258 }

QWidget * QAction::parentWidget (  )  const

Returns the parent widget.

Definition at line 298 of file qaction.cpp.

References QObject::isWidgetType(), and QObject::parent().

Referenced by QAbstractFormBuilder::createDom().

00299 {
00300     QObject *ret = parent();
00301     while (ret && !ret->isWidgetType())
00302         ret = ret->parent();
00303     return (QWidget*)ret;
00304 }

Here is the call graph for this function:

QList< QWidget * > QAction::associatedWidgets (  )  const

Since:
4.2 Returns a list of widgets this action has been added to.
See also:
QWidget::addAction()

Definition at line 312 of file qaction.cpp.

References d.

00313 {
00314     Q_D(const QAction);
00315     return d->widgets;
00316 }

bool QAction::event ( QEvent e  )  [protected, virtual]

Reimplemented from QObject.

Definition at line 980 of file qaction.cpp.

References activate(), QObject::event(), qWarning(), QEvent::Shortcut, and QEvent::type().

Referenced by QWidgetAction::event().

00981 {
00982 #ifndef QT_NO_SHORTCUT
00983     if (e->type() == QEvent::Shortcut) {
00984         QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
00985         Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()),
00986                    "QAction::event",
00987                    "Received shortcut event from incorrect shortcut");
00988         if (se->isAmbiguous())
00989             qWarning("QAction::eventFilter: Ambiguous shortcut overload: %s", QString(se->key()).toLatin1().constData());
00990         else
00991             activate(Trigger);
00992         return true;
00993     }
00994 #endif
00995     return QObject::event(e);
00996 }

Here is the call graph for this function:

void QAction::trigger (  )  [inline, slot]

This is a convenience slot that calls activate(Trigger).

Definition at line 175 of file qaction.h.

Referenced by QDesignerWorkbench::addFormWindow(), MainWindow::checkCurrentStyle(), and qdesigner_internal::FormWindow::editWidgets().

00175 { activate(Trigger); }

void QAction::hover (  )  [inline, slot]

This is a convenience slot that calls activate(Hover).

Definition at line 176 of file qaction.h.

00176 { activate(Hover); }

void QAction::setChecked ( bool   )  [slot]

Definition at line 888 of file qaction.cpp.

References d, emit, and toggled().

Referenced by QWorkspacePrivate::_q_updateActions(), activate(), addAction(), QDesignerWorkbench::addFormWindow(), TextEdit::alignmentChanged(), QDesignerFormWindow::changeEvent(), QPixelTool::contextMenuEvent(), qdesigner_internal::createCheckableAction(), QVFb::enableCursor(), TextEdit::fontChanged(), QDesignerToolWindow::hideEvent(), QWorkspacePrivate::init(), Q3MainWindow::menuAboutToShow(), QDesignerActions::QDesignerActions(), QFileDialogPrivate::setDirFilter(), QFileDialogPrivate::setDirSorting(), QFileDialogPrivate::setupActions(), MainWindow::setupDockWidgets(), QDesignerToolWindow::showEvent(), QDesignerWorkbench::switchToTopLevelMode(), toggle(), qdesigner_internal::RichTextEditorToolBar::updateActions(), ColorSwatch::updateContextMenu(), ToolBar::updateMenu(), and MainWindow::updateWindowMenu().

00889 {
00890     Q_D(QAction);
00891     if (!d->checkable || d->checked == b)
00892         return;
00893 
00894     QPointer<QAction> guard(this);
00895     d->checked = b;
00896     d->sendDataChanged();
00897     if (guard)
00898         emit toggled(b);
00899 }

void QAction::toggle (  )  [slot]

This is a convenience function for the checked property. Connect to it to change the checked state to its opposite state.

Definition at line 873 of file qaction.cpp.

References d, and setChecked().

00874 {
00875     Q_D(QAction);
00876     setChecked(!d->checked);
00877 }

void QAction::setEnabled ( bool   )  [slot]

Definition at line 927 of file qaction.cpp.

References d, and qApp.

Referenced by QFileDialogPrivate::_q_showContextMenu(), QWorkspacePrivate::_q_updateActions(), qdesigner_internal::ActionEditor::ActionEditor(), QView3DPlugin::activeFormWindowChanged(), qdesigner_internal::BuddyEditorPlugin::activeFormWindowChanged(), qdesigner_internal::SignalSlotEditorPlugin::activeFormWindowChanged(), QDesignerActions::activeFormWindowChanged(), qdesigner_internal::TabOrderEditorPlugin::activeFormWindowChanged(), QDesignerWorkbench::addFormWindow(), ToolBar::addSpinBox(), QtWindowListMenu::addWindow(), ColorSwatch::allow(), ToolBar::allow(), TextEdit::clipboardDataChanged(), SourceTextEdit::contextMenuEvent(), QAbstractSpinBox::contextMenuEvent(), QPixelTool::contextMenuEvent(), qdesigner_internal::QtGradientStopsWidget::contextMenuEvent(), ImageViewer::createActions(), MainWindow::createLetter(), QUndoStack::createRedoAction(), QUndoGroup::createRedoAction(), QUndoStack::createUndoAction(), QUndoGroup::createUndoAction(), qdesigner_internal::SignalSlotEditorPlugin::initialize(), qdesigner_internal::BuddyEditorPlugin::initialize(), qdesigner_internal::TabOrderEditorPlugin::initialize(), ConnectionWidget::on_tree_currentItemChanged(), ImageViewer::open(), MainWindow::openIniFile(), MainWindow::openPropertyList(), MainWindow::openRegistryPath(), MainWindow::openSettings(), ToolBar::order(), ToolBar::place(), ColorSwatch::place(), QDesignerActions::QDesignerActions(), QtWindowListMenu::QtWindowListMenu(), ToolBar::randomize(), QDesignerWorkbench::removeFormWindow(), ToolBar::removeSpinBox(), ImageViewer::scaleImage(), MainWindow::setActionsEnabled(), QtWindowListMenu::setEnabled(), qdesigner_internal::ActionEditor::setFormWindow(), MainWindow::setSettingsObject(), qdesigner_internal::FormWindowManager::setupActions(), TextEdit::setupEditActions(), Window::setVisible(), qdesigner_internal::ActionEditor::slotItemChanged(), qdesigner_internal::FormWindowManager::slotUpdateActions(), QDesignerTabWidget::tabInserted(), QDesignerTabWidget::tabRemoved(), qdesigner_internal::ContainerWidgetTaskMenu::taskActions(), TextEdit::TextEdit(), ToolBar::ToolBar(), ImageViewer::updateActions(), ColorSwatch::updateContextMenu(), ToolBar::updateMenu(), MainWindow::updateMenus(), and MainWindow::updateStyles().

00928 {
00929     Q_D(QAction);
00930     if (b == d->enabled && b != d->forceDisabled)
00931         return;
00932     d->forceDisabled = !b;
00933     if (b && d->group && !d->group->isEnabled())
00934         return;
00935     d->enabled = b;
00936 #ifndef QT_NO_SHORTCUT
00937     d->setShortcutEnabled(b, qApp->d_func()->shortcutMap);
00938 #endif
00939     d->sendDataChanged();
00940 }

void QAction::setDisabled ( bool  b  )  [inline, slot]

This is a convenience function for the enabled property, that is useful for signals--slots connections. If b is true the action is disabled; otherwise it is enabled.

Definition at line 180 of file qaction.h.

00180 { setEnabled(!b); }

void QAction::setVisible ( bool   )  [slot]

Definition at line 959 of file qaction.cpp.

References d.

Referenced by MainWindow::aboutToShowSaveAsMenu(), QDesignerWorkbench::changeBringToFrontVisiblity(), QDesignerActions::QDesignerActions(), QWidgetAction::setDefaultWidget(), QDesignerWorkbench::switchToDockedMode(), QDesignerWorkbench::switchToTopLevelMode(), MainWindow::updateMenus(), MainWindow::updateRecentFileActions(), and MainWindow::updateWindowMenu().

00960 {
00961     Q_D(QAction);
00962     if (b == d->visible && b != d->forceInvisible)
00963         return;
00964     d->forceInvisible = !b;
00965     d->visible = b;
00966     d->sendDataChanged();
00967 }

void QAction::changed (  )  [signal]

This signal is emitted when an action has changed. If you are only interested in actions in a given widget, you can watch for QWidget::actionEvent() sent with an QEvent::ActionChanged.

See also:
QWidget::actionEvent()

void QAction::triggered ( bool  checked = false  )  [signal]

This signal is emitted when an action is activated by the user; for example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination, or when trigger() was called. Notably, it is not emitted when setChecked() or toggle() is called.

If the action is checkable, checked is true if the action is checked, or false if the action is unchecked.

See also:
QAction::activate(), QAction::toggled(), checked

Referenced by activate(), and QWhatsThisAction::QWhatsThisAction().

void QAction::hovered (  )  [signal]

This signal is emitted when an action is highlighted by the user; for example, when the user pauses with the cursor over a menu option, toolbar button, or presses an action's shortcut key combination.

See also:
QAction::activate()

Referenced by activate().

void QAction::toggled ( bool  checked  )  [signal]

This signal is emitted whenever a checkable action changes its isChecked() status. This can be the result of a user interaction, or because setChecked() was called.

checked is true if the action is checked, or false if the action is unchecked.

See also:
QAction::activate(), QAction::triggered(), checked

Referenced by setChecked().


Friends And Related Function Documentation

friend class QWidget [friend]

Reimplemented from QObject.

Definition at line 198 of file qaction.h.

friend class QActionGroup [friend]

Definition at line 199 of file qaction.h.

friend class QMenu [friend]

Definition at line 200 of file qaction.h.

friend class QMenuBar [friend]

Definition at line 201 of file qaction.h.

friend class QShortcutMap [friend]

Definition at line 202 of file qaction.h.

friend class QToolButton [friend]

Definition at line 203 of file qaction.h.


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:49:21 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1