|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QMenu
public class QMenu
The QMenu
class provides a menu widget for use in menu bars, context menus, and other popup menus. A menu widget is a selection menu. It can be either a pull-down menu in a menu bar or a standalone context menu. Pull-down menus are shown by the menu bar when the user clicks on the respective item or presses the specified shortcut key. Use QMenuBar::addMenu()
to insert a menu into a menu bar. Context menus are usually invoked by some special keyboard key or by right-clicking. They can be executed either asynchronously with popup()
or synchronously with exec()
. Menus can also be invoked in response to button presses; these are just like context menus except for how they are invoked.
![]() |
![]() |
![]() |
A menu shown in Plastique widget style, Windows XP widget style, and Macintosh widget style. |
addAction()
. An action is represented vertically and rendered by QStyle
. In addition, actions can have a text label, an optional icon drawn on the very left side, and shortcut key sequence such as "Ctrl+X". There are three kinds of action items: separators, actions that show a submenu, and actions that perform an action. Separators are inserted with addSeparator()
. For submenus use addMenu()
. All other items are considered action items.
When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is triggered()
. In addition, QMenu
provides two signals, activated() and highlighted(), which signal the QAction
that was triggered from the menu.
You clear a menu with clear()
and remove individual action items with removeAction()
.
A QMenu
can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to "tear off" frequently used menus and position them in a convenient place on the screen. If you want this functionality for a particular menu, insert a tear-off handle with setTearOffEnabled()
. When using tear-off menus, bear in mind that the concept isn't typically used on Microsoft Windows so some users may not be familiar with it. Consider using a QToolBar
instead.QMenu on Qt/CE
If a menu is integrated into the native menubar on Windows Mobile we do not support the signals: aboutToHide
(), aboutToShow
() and hovered (). It is not possible to display an icon in a native menu on Windows Mobile.
See the Menus example for an example of how to use QMenuBar
and QMenu
in your application.
Important inherited functions: addAction()
, removeAction()
, clear()
, addSeparator()
, and addMenu()
.
QMenuBar
, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Application Example, Menus Example, and Recent Files Example.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Field Summary | |
---|---|
QSignalEmitter.Signal0 |
aboutToHide
This signal is emitted just before the menu is hidden from the user. |
QSignalEmitter.Signal0 |
aboutToShow
This signal is emitted just before the menu is shown to the user. |
QSignalEmitter.Signal1 |
hovered
This signal is emitted when a menu action is highlighted; action is the action that caused the signal to be emitted. |
QSignalEmitter.Signal1 |
triggered
This signal is emitted when an action in this menu is triggered; action is the action that caused the signal to be emitted. |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QMenu()
Constructs a menu with parent parent. |
|
QMenu(QWidget parent)
Constructs a menu with parent parent. |
|
QMenu(java.lang.String title)
Constructs a menu with a title and a parent. |
|
QMenu(java.lang.String title,
QWidget parent)
Constructs a menu with a title and a parent. |
Method Summary | |
---|---|
QAction |
actionAt(QPoint arg__1)
Returns the item at pt; returns 0 if there is no item there. |
QRect |
actionGeometry(QAction arg__1)
Returns the geometry of action act. |
QAction |
activeAction()
Returns the currently highlighted action, or 0 if no action is currently highlighted. |
QAction |
addAction(QIcon icon,
java.lang.String text)
This convenience function creates a new action with an icon and some text. |
QAction |
addAction(QIcon icon,
java.lang.String text,
java.lang.Object receiver,
java.lang.String method)
This method creates a new action with the given icon and text. |
QAction |
addAction(QIcon icon,
java.lang.String text,
java.lang.Object receiver,
java.lang.String method,
QKeySequence shortcut)
This function creates a new action with the given icon, shortcut, and text. |
QAction |
addAction(QIcon icon,
java.lang.String text,
QSignalEmitter.AbstractSignal signal)
|
QAction |
addAction(QIcon icon,
java.lang.String text,
QSignalEmitter.AbstractSignal signal,
QKeySequence shortcut)
|
QAction |
addAction(java.lang.String text)
This convenience function creates a new action with text. |
QAction |
addAction(java.lang.String text,
java.lang.Object receiver,
java.lang.String method)
This convenience function creates a new action with the text text. |
QAction |
addAction(java.lang.String text,
java.lang.Object receiver,
java.lang.String method,
QKeySequence shortcut)
This convenience function creates a new action with the text text. |
QAction |
addAction(java.lang.String text,
QSignalEmitter.AbstractSignal signal)
|
QAction |
addAction(java.lang.String text,
QSignalEmitter.AbstractSignal signal,
QKeySequence shortcut)
|
QMenu |
addMenu(QIcon icon,
java.lang.String title)
Appends a new QMenu with icon and title to the menu. |
QAction |
addMenu(QMenu menu)
This convenience function adds menu as a submenu to this menu. |
QMenu |
addMenu(java.lang.String title)
Appends a new QMenu with title to the menu. |
QAction |
addSeparator()
This convenience function creates a new separator action, i.e. |
void |
clear()
Removes all the menu's actions. |
protected int |
columnCount()
If a menu does not fit on the screen it lays itself out so that it does fit. |
QAction |
defaultAction()
Returns the current default action. |
QAction |
exec()
Executes this menu synchronously. |
static QAction |
exec(java.util.List actions,
QPoint pos)
Executes this menu synchronously. |
static QAction |
exec(java.util.List actions,
QPoint pos,
QAction at)
Executes this menu synchronously. |
QAction |
exec(QPoint pos)
Executes this menu synchronously. |
QAction |
exec(QPoint pos,
QAction at)
Executes this menu synchronously. |
static QMenu |
fromNativePointer(QNativePointer nativePointer)
|
void |
hideTearOffMenu()
This function will forcibly hide the torn off menu making it disappear from the users desktop. |
QIcon |
icon()
This property holds The icon of the menu. |
protected void |
initStyleOption(QStyleOptionMenuItem option,
QAction action)
Initialize option with the values from this menu and information from action. |
QAction |
insertMenu(QAction before,
QMenu menu)
This convenience function inserts menu before action before and returns the menus menuAction() . |
QAction |
insertSeparator(QAction before)
This convenience function creates a new separator action, i.e. |
boolean |
isEmpty()
Returns true if there are no visible actions inserted into the menu, false otherwise. |
boolean |
isTearOffEnabled()
This property holds whether the menu supports being torn off. |
boolean |
isTearOffMenuVisible()
When a menu is torn off a second menu is shown to display the menu contents in a new window. |
QAction |
menuAction()
Returns the action associated with this menu. |
void |
popup(QPoint pos)
Displays the menu so that the action atAction will be at the specified global position p. |
void |
popup(QPoint pos,
QAction at)
Displays the menu so that the action atAction will be at the specified global position p. |
boolean |
separatorsCollapsible()
This property holds whether consecutive separators should be collapsed. |
void |
setActiveAction(QAction act)
Sets the currently highlighted action to act. |
void |
setDefaultAction(QAction arg__1)
This will set the default action to act. |
void |
setIcon(QIcon icon)
This property holds The icon of the menu. |
void |
setSeparatorsCollapsible(boolean collapse)
This property holds whether consecutive separators should be collapsed. |
void |
setTearOffEnabled(boolean arg__1)
This property holds whether the menu supports being torn off. |
void |
setTitle(java.lang.String title)
This property holds The title of the menu. |
java.lang.String |
title()
This property holds The title of the menu. |
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 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 aboutToHide
aboutToShow()
, and hide()
.
public final QSignalEmitter.Signal0 aboutToShow
aboutToHide()
, and show()
.
public final QSignalEmitter.Signal1 hovered
Often this is used to update status information.
triggered()
, and QAction::hovered()
.
public final QSignalEmitter.Signal1 triggered
Normally, you connect each menu action's triggered()
signal to its own custom slot, but sometimes you will want to connect several actions to a single slot, for example, when you have a group of closely related actions, such as "left justify", "center", "right justify".
hovered()
, and QAction::triggered()
.
Constructor Detail |
---|
public QMenu()
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject
).
public QMenu(QWidget parent)
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject
).
public QMenu(java.lang.String title)
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject
).
title
.
public QMenu(java.lang.String title, QWidget parent)
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject
).
title
.
Method Detail |
---|
public final QAction actionAt(QPoint arg__1)
public final QRect actionGeometry(QAction arg__1)
public final QAction activeAction()
setActiveAction()
.
public final QAction addAction(QIcon icon, java.lang.String text)
QWidget::addAction()
.
public final QAction addAction(java.lang.String text)
QWidget::addAction()
.
public final QAction addMenu(QMenu menu)
menuAction()
. QWidget::addAction()
, and QMenu::menuAction()
.
public final QMenu addMenu(QIcon icon, java.lang.String title)
QMenu
with icon and title to the menu. The menu takes ownership of the menu. Returns the new menu. QWidget::addAction()
, and QMenu::menuAction()
.
public final QMenu addMenu(java.lang.String title)
QMenu
with title to the menu. The menu takes ownership of the menu. Returns the new menu. QWidget::addAction()
, and QMenu::menuAction()
.
public final QAction addSeparator()
QAction::isSeparator()
returning true, and adds the new action to this menu's list of actions. It returns the newly created action. QWidget::addAction()
.
public final void clear()
removeAction()
.
protected final int columnCount()
This functions returns the number of columns necessary.
public final QAction defaultAction()
setDefaultAction()
.
public final QAction exec()
This is equivalent to exec(pos()).
This returns the triggered QAction
in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
In most situations you'll want to specify the position yourself, for example, the current mouse position:
exec(QCursor::pos());or aligned to a widget:
exec(somewidget.mapToGlobal(QPoint(0,0)));or in reaction to a
QMouseEvent
*e: exec(e->globalPos());
public final QAction exec(QPoint pos)
Pops up the menu so that the action action will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal()
.
This returns the triggered QAction
in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
Note that all signals are emitted as usual. If you connect a QAction
to a slot and call the menu's exec()
, you get the result both via the signal-slot connection and in the return value of exec()
.
Common usage is to position the menu at the current mouse position:
exec(QCursor::pos());or aligned to a widget:
exec(somewidget.mapToGlobal(QPoint(0, 0)));or in reaction to a
QMouseEvent
*e: exec(e->globalPos());When positioning a menu with
exec()
or popup()
, bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint()
which calculates the proper size depending on the menu's current contents. popup()
, and QWidget::mapToGlobal()
.
public final QAction exec(QPoint pos, QAction at)
Pops up the menu so that the action action will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal()
.
This returns the triggered QAction
in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
Note that all signals are emitted as usual. If you connect a QAction
to a slot and call the menu's exec()
, you get the result both via the signal-slot connection and in the return value of exec()
.
Common usage is to position the menu at the current mouse position:
exec(QCursor::pos());or aligned to a widget:
exec(somewidget.mapToGlobal(QPoint(0, 0)));or in reaction to a
QMouseEvent
*e: exec(e->globalPos());When positioning a menu with
exec()
or popup()
, bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint()
which calculates the proper size depending on the menu's current contents. popup()
, and QWidget::mapToGlobal()
.
public final void hideTearOffMenu()
isTearOffMenuVisible()
, and isTearOffEnabled()
.
public final QIcon icon()
QAction::icon
property of the menuAction()
.
public final QAction insertMenu(QAction before, QMenu menu)
menuAction()
. QWidget::insertAction()
, and addMenu()
.
public final QAction insertSeparator(QAction before)
QAction::isSeparator()
returning true. The function inserts the newly created action into this menu's list of actions before action before and returns it. QWidget::insertAction()
, and addSeparator()
.
public final boolean isEmpty()
QWidget::actions()
.
public final boolean isTearOffEnabled()
QMenu
has a special menu item (often shown as a dashed line at the top of the menu) that creates a copy of the menu when the tear-off menu item is triggered. This "torn-off" copy lives in a separate window. It contains the same menu items as the original menu, with the exception of the tear-off handle.
public final boolean isTearOffMenuVisible()
hideTearOffMenu()
, and isTearOffEnabled()
.
public final QAction menuAction()
public final void popup(QPoint pos)
QWidget::mapToGlobal()
. When positioning a menu with exec()
or popup()
, bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary, so in many cases, the size before and after the show is different. Instead, use sizeHint()
which calculates the proper size depending on the menu's current contents.
QWidget::mapToGlobal()
, and exec()
.
public final void popup(QPoint pos, QAction at)
QWidget::mapToGlobal()
. When positioning a menu with exec()
or popup()
, bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary, so in many cases, the size before and after the show is different. Instead, use sizeHint()
which calculates the proper size depending on the menu's current contents.
QWidget::mapToGlobal()
, and exec()
.
public final boolean separatorsCollapsible()
public final void setActiveAction(QAction act)
activeAction()
.
public final void setDefaultAction(QAction arg__1)
QStyle
. A default action is usually meant to indicate what will defaultly happen on a drop, as shown in a context menu. defaultAction()
.
public final void setIcon(QIcon icon)
QAction::icon
property of the menuAction()
.
public final void setSeparatorsCollapsible(boolean collapse)
public final void setTearOffEnabled(boolean arg__1)
QMenu
has a special menu item (often shown as a dashed line at the top of the menu) that creates a copy of the menu when the tear-off menu item is triggered. This "torn-off" copy lives in a separate window. It contains the same menu items as the original menu, with the exception of the tear-off handle.
public final void setTitle(java.lang.String title)
QAction::text
property of the menuAction()
.
public final java.lang.String title()
QAction::text
property of the menuAction()
.
public static QAction exec(java.util.List actions, QPoint pos)
The menu's actions are specified by the list of actions. The menu will pop up so that the specified action, at, appears at global position pos. If at is not specified then the menu appears at position pos.
The function returns the triggered QAction
in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
This is equivalent to:
QMenu menu; QAction *at = actions[0]; // Assumes actions is not empty foreach (QAction *a, actions) menu.addAction(a); menu.exec(pos, at);
popup()
, and QWidget::mapToGlobal()
.
public static QAction exec(java.util.List actions, QPoint pos, QAction at)
The menu's actions are specified by the list of actions. The menu will pop up so that the specified action, at, appears at global position pos. If at is not specified then the menu appears at position pos.
The function returns the triggered QAction
in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
This is equivalent to:
QMenu menu; QAction *at = actions[0]; // Assumes actions is not empty foreach (QAction *a, actions) menu.addAction(a); menu.exec(pos, at);
popup()
, and QWidget::mapToGlobal()
.
public static QMenu fromNativePointer(QNativePointer nativePointer)
protected final void initStyleOption(QStyleOptionMenuItem option, QAction action)
public final QAction addAction(java.lang.String text, java.lang.Object receiver, java.lang.String method, QKeySequence shortcut)
public final QAction addAction(java.lang.String text, QSignalEmitter.AbstractSignal signal, QKeySequence shortcut)
public final QAction addAction(java.lang.String text, java.lang.Object receiver, java.lang.String method)
public final QAction addAction(java.lang.String text, QSignalEmitter.AbstractSignal signal)
public final QAction addAction(QIcon icon, java.lang.String text, java.lang.Object receiver, java.lang.String method, QKeySequence shortcut)
public final QAction addAction(QIcon icon, java.lang.String text, QSignalEmitter.AbstractSignal signal, QKeySequence shortcut)
public final QAction addAction(QIcon icon, java.lang.String text, java.lang.Object receiver, java.lang.String method)
public final QAction addAction(QIcon icon, java.lang.String text, QSignalEmitter.AbstractSignal signal)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |