|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QAction
public class QAction
The QAction
class provides an abstract user interface action that can be inserted into widgets. 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()
. Note that an action must be added to a widget before it can be used; this is also true when the shortcut should be global (i.e., Qt::ApplicationShortcut
as Qt::ShortcutContext
).
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:
The following code example is written in c++.
openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); openAct->setShortcut(tr("Ctrl+O")); openAct->setStatusTip(tr("Open an existing file")); connect(openAct, SIGNAL(triggered()), this, SLOT(open()));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.
fileMenu->addAction(openAct); fileToolBar->addAction(openAct);
QMenu
, QToolBar
, and Application Example.
Nested Class Summary | |
---|---|
static class |
QAction.ActionEvent
This enum type is used when calling QAction::activate() |
static class |
QAction.MenuRole
This enum describes how an action should be moved into the application menu on Mac OS X. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal0 |
changed
This signal is emitted when an action has changed. |
QSignalEmitter.Signal0 |
hovered
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. |
QSignalEmitter.Signal1 |
toggled
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
triggered
This signal takes 1 generic argument(s). |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QAction(QIcon icon,
java.lang.String text,
QObject parent)
Constructs an action with an icon and some text and parent. |
|
QAction(QObject parent)
Constructs an action with parent. |
|
QAction(java.lang.String text,
QObject parent)
Constructs an action with some text and parent. |
Method Summary | |
---|---|
QActionGroup |
actionGroup()
Returns the action group for this action. |
void |
activate(QAction.ActionEvent event)
Sends the relevant signals for ActionEvent event. |
java.util.List |
associatedWidgets()
Returns a list of widgets this action has been added to. |
boolean |
autoRepeat()
This property holds whether the action can auto repeat. |
java.lang.Object |
data()
Returns the user data as set in QAction.:setData. |
QFont |
font()
This property holds the action's font. |
void |
hover()
This is a convenience slot that calls activate(Hover). |
QIcon |
icon()
This property holds the action's icon. |
java.lang.String |
iconText()
This property holds the action's descriptive icon text. |
boolean |
isCheckable()
This property holds whether the action is a checkable action. |
boolean |
isChecked()
This property holds whether the action is checked. |
boolean |
isEnabled()
This property holds whether the action is enabled. |
boolean |
isIconVisibleInMenu()
This property holds Whether or not an action should show an icon in a menu. |
boolean |
isSeparator()
Returns true if this action is a separator action; otherwise it returns false. |
boolean |
isVisible()
This property holds whether the action can be seen (e.g. |
QMenu |
menu()
Returns the menu contained by this action. |
QAction.MenuRole |
menuRole()
This property holds the action's menu role. |
QWidget |
parentWidget()
Returns the parent widget. |
void |
setActionGroup(QActionGroup group)
Sets this action group to group. |
void |
setAutoRepeat(boolean arg__1)
This property holds whether the action can auto repeat. |
void |
setCheckable(boolean arg__1)
This property holds whether the action is a checkable action. |
void |
setChecked(boolean arg__1)
This property holds whether the action is checked. |
void |
setData(java.lang.Object var)
Sets the action's internal data to the given userData. |
void |
setDisabled(boolean b)
This is a convenience function for the enabled property, that is useful for signals--slots connections. |
void |
setEnabled(boolean arg__1)
This property holds whether the action is enabled. |
void |
setFont(QFont font)
This property holds the action's font. |
void |
setIcon(QIcon icon)
This property holds the action's icon. |
void |
setIcon(QPixmap pm)
|
void |
setIconText(java.lang.String text)
This property holds the action's descriptive icon text. |
void |
setIconVisibleInMenu(boolean visible)
This property holds Whether or not an action should show an icon in a menu. |
void |
setMenu(QMenu menu)
Sets the menu contained by this action to the specified menu. |
void |
setMenuRole(QAction.MenuRole menuRole)
This property holds the action's menu role. |
void |
setSeparator(boolean b)
If b is true then this action will be considered a separator. |
void |
setShortcut(QKeySequence.StandardKey key)
Sets the shortcut to the key sequence for the given key. |
void |
setShortcut(QKeySequence shortcut)
This property holds the action's primary shortcut key. |
void |
setShortcut(java.lang.String key)
Sets the shortcut to the key sequence for the given key string. |
void |
setShortcutContext(Qt.ShortcutContext context)
This property holds the context for the action's shortcut. |
void |
setShortcuts(java.util.List shortcuts)
Sets shortcuts as the list of shortcuts that trigger the action. |
void |
setShortcuts(QKeySequence.StandardKey arg__1)
Sets a platform dependent list of shortcuts based on the key. |
void |
setStatusTip(java.lang.String statusTip)
This property holds the action's status tip. |
void |
setText(java.lang.String text)
This property holds the action's descriptive text. |
void |
setToolTip(java.lang.String tip)
This property holds the action's tooltip. |
void |
setVisible(boolean arg__1)
This property holds whether the action can be seen (e.g. |
void |
setWhatsThis(java.lang.String what)
This property holds the action's "What's This?" help text. |
QKeySequence |
shortcut()
This property holds the action's primary shortcut key. |
Qt.ShortcutContext |
shortcutContext()
This property holds the context for the action's shortcut. |
java.util.List |
shortcuts()
Returns the list of shortcuts, with the primary shortcut as the first element of the list. |
boolean |
showStatusText()
Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent widget. |
boolean |
showStatusText(QWidget widget)
Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent widget. |
java.lang.String |
statusTip()
This property holds the action's status tip. |
java.lang.String |
text()
This property holds the action's descriptive text. |
void |
toggle()
This is a convenience function for the checked property. |
java.lang.String |
toolTip()
This property holds the action's tooltip. |
void |
trigger()
This is a convenience slot that calls activate(Trigger). |
java.lang.String |
whatsThis()
This property holds the action's "What's This?" help text. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal0 changed
QWidget::actionEvent()
sent with an QEvent::ActionChanged
. QWidget::actionEvent()
.
public final QSignalEmitter.Signal0 hovered
QAction::activate()
.
public final QSignalEmitter.Signal1 toggled
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Boolean(named: checked)>:
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.
QAction::activate()
, QAction::triggered()
, and checked
.
public final QSignalEmitter.Signal1 triggered
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Boolean(named: checked)>:
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.
QAction::activate()
, QAction::toggled()
, and checked
.
Constructor Detail |
---|
public QAction(QObject parent)
public QAction(QIcon icon, java.lang.String text, QObject parent)
The action uses a stripped version of text (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 will be used for tooltips unless you specify a different text using setToolTip()
.
public QAction(java.lang.String text, QObject parent)
The action uses a stripped version of text (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 will be used for tooltips unless you specify a different text using setToolTip()
.
Method Detail |
---|
public final QActionGroup actionGroup()
QActionGroup
, and QAction::setActionGroup()
.
public final void activate(QAction.ActionEvent event)
ActionEvent
event. Action based widgets use this API to cause the QAction
to emit signals as well as emitting their own.
public final java.util.List associatedWidgets()
QWidget::addAction()
.
public final boolean autoRepeat()
public final java.lang.Object data()
setData()
.
public final QFont font()
QAction
. The font will can be considered a hint as it will not be consulted in all cases based upon application and style. By default, this property contains the application's default font.
QAction::setText()
, and QStyle
.
public final void hover()
public final QIcon icon()
If a null icon (QIcon::isNull()
is passed into this function, the icon of the action is cleared.
public final java.lang.String iconText()
QToolBar::toolButtonStyle
is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button. It also serves as the default text in menus and tooltips if the action has not been defined with setText()
or setToolTip()
, and will also be used in toolbar buttons if no icon has been defined using setIcon()
.
If the icon text is not explicitly set, the action's normal text will be used for the icon text.
By default, this property contains an empty string.
setToolTip()
, and setStatusTip()
.
public final boolean isCheckable()
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.
QAction::setChecked()
.
public final boolean isChecked()
checkable
.
public final boolean isEnabled()
What's This? help on disabled actions is still available, provided that the QAction::whatsThis
property is set.
By default, this property is true (actions are enabled).
text
.
public final boolean isIconVisibleInMenu()
The default is to follow whether the Qt::AA_DontShowIconsInMenus
attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.
For example:
QApplication.initialize(args); QApplication.setAttribute(Qt.ApplicationAttribute.AA_DontShowIconsInMenus); // Icons are *no longer shown* in menus // ... QAction myAction = new QAction(window); // ... myAction.setIcon(SomeIcon); myAction.setIconVisibleInMenu(true); // Icon *will* be shown in menus for *this* action.
QAction::icon
, and QApplication::setAttribute()
.
public final boolean isSeparator()
QAction::setSeparator()
.
public final boolean isVisible()
Actions which are not visible are not grayed out; they do not appear at all.
By default, this property is true (actions are visible).
public final QMenu menu()
setMenu()
, and QMenu::addAction()
.
public final QAction.MenuRole menuRole()
TextHeuristicRole
, which means that the action is added based on its text (see QMenuBar
for more information). The menu role can only be changed before the actions are put into the menu bar in Mac OS X (usually just before the first application window is shown).
public final QWidget parentWidget()
public final void setActionGroup(QActionGroup group)
Actions within the group will be mutually exclusive.
QActionGroup
, and QAction::actionGroup()
.
public final void setAutoRepeat(boolean arg__1)
public final void setCheckable(boolean arg__1)
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.
QAction::setChecked()
.
public final void setChecked(boolean arg__1)
checkable
.
public final void setData(java.lang.Object var)
data()
.
public final void setDisabled(boolean b)
enabled
property, that is useful for signals--slots connections. If b is true the action is disabled; otherwise it is enabled.
public final void setEnabled(boolean arg__1)
What's This? help on disabled actions is still available, provided that the QAction::whatsThis
property is set.
By default, this property is true (actions are enabled).
text
.
public final void setFont(QFont font)
QAction
. The font will can be considered a hint as it will not be consulted in all cases based upon application and style. By default, this property contains the application's default font.
QAction::setText()
, and QStyle
.
public final void setIcon(QIcon icon)
If a null icon (QIcon::isNull()
is passed into this function, the icon of the action is cleared.
public final void setIconText(java.lang.String text)
QToolBar::toolButtonStyle
is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button. It also serves as the default text in menus and tooltips if the action has not been defined with setText()
or setToolTip()
, and will also be used in toolbar buttons if no icon has been defined using setIcon()
.
If the icon text is not explicitly set, the action's normal text will be used for the icon text.
By default, this property contains an empty string.
setToolTip()
, and setStatusTip()
.
public final void setIconVisibleInMenu(boolean visible)
The default is to follow whether the Qt::AA_DontShowIconsInMenus
attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.
For example:
QApplication.initialize(args); QApplication.setAttribute(Qt.ApplicationAttribute.AA_DontShowIconsInMenus); // Icons are *no longer shown* in menus // ... QAction myAction = new QAction(window); // ... myAction.setIcon(SomeIcon); myAction.setIconVisibleInMenu(true); // Icon *will* be shown in menus for *this* action.
QAction::icon
, and QApplication::setAttribute()
.
public final void setMenu(QMenu menu)
menu()
.
public final void setMenuRole(QAction.MenuRole menuRole)
TextHeuristicRole
, which means that the action is added based on its text (see QMenuBar
for more information). The menu role can only be changed before the actions are put into the menu bar in Mac OS X (usually just before the first application window is shown).
public final void setSeparator(boolean b)
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.
QAction::isSeparator()
.
public final void setShortcut(QKeySequence shortcut)
Qt::Key
and Qt::Modifier
. There is no default shortcut key.
public final void setShortcutContext(Qt.ShortcutContext context)
Qt::ShortcutContext
. The default value is Qt::WindowShortcut
.
public final void setShortcuts(QKeySequence.StandardKey arg__1)
QKeySequence::keyBindings()
.
public final void setShortcuts(java.util.List shortcuts)
shortcuts()
, and shortcut
.
public final void setStatusTip(java.lang.String statusTip)
By default, this property contains an empty string.
setToolTip()
, and showStatusText()
.
public final void setText(java.lang.String text)
setText()
, the action's description icon text will be used as text. There is no default text. iconText
.
public final void setToolTip(java.lang.String tip)
By default, this property contains the action's text.
setStatusTip()
, and setShortcut()
.
public final void setVisible(boolean arg__1)
Actions which are not visible are not grayed out; they do not appear at all.
By default, this property is true (actions are visible).
public final void setWhatsThis(java.lang.String what)
QWhatsThis
, and Q3StyleSheet.
public final QKeySequence shortcut()
Qt::Key
and Qt::Modifier
. There is no default shortcut key.
public final Qt.ShortcutContext shortcutContext()
Qt::ShortcutContext
. The default value is Qt::WindowShortcut
.
public final java.util.List shortcuts()
setShortcuts()
.
public final boolean showStatusText()
QStatusTipEvent
to its parent widget. Returns true if an event was sent; otherwise returns false. If a null widget is specified, the event is sent to the action's parent.
statusTip
.
public final boolean showStatusText(QWidget widget)
QStatusTipEvent
to its parent widget. Returns true if an event was sent; otherwise returns false. If a null widget is specified, the event is sent to the action's parent.
statusTip
.
public final java.lang.String statusTip()
By default, this property contains an empty string.
setToolTip()
, and showStatusText()
.
public final java.lang.String text()
setText()
, the action's description icon text will be used as text. There is no default text. iconText
.
public final void toggle()
checked
property. Connect to it to change the checked state to its opposite state.
public final java.lang.String toolTip()
By default, this property contains the action's text.
setStatusTip()
, and setShortcut()
.
public final void trigger()
public final java.lang.String whatsThis()
QWhatsThis
, and Q3StyleSheet.
public final void setShortcut(java.lang.String key)
key
- The description of the key sequence. Typically used with tr()
so key sequences can be locale aware.public final void setShortcut(QKeySequence.StandardKey key)
key
- The key for which to select a key sequencepublic final void setIcon(QPixmap pm)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |