Qt Jambi Home

com.trolltech.qt.gui
Class QMenu

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QMenu
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QMenu
extends QWidget

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.

A menu consists of a list of action items. Actions are added with 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.

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.

See Also:
QMenuBar, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Application Example, Menus Example, 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<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
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<QAction> hovered
          This signal is emitted when a menu action is highlighted; action is the action that caused the signal to be emitted.
 QSignalEmitter.Signal1<QAction> 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()
          Equivalent to QMenu(0).
QMenu(QWidget parent)
          Constructs a menu with parent parent.
QMenu(java.lang.String title)
          Equivalent to QMenu(title, 0).
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 arg__1; returns 0 if there is no item there.
protected  void actionEvent(QActionEvent arg__1)
          

This event handler is called with the given arg__1 whenever the widget's actions are changed.

 QRect actionGeometry(QAction arg__1)
          Returns the geometry of action arg__1.
 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)
          This method creates an action with the given icon and text.
 QAction addAction(QIcon icon, java.lang.String text, QSignalEmitter.AbstractSignal signal, QKeySequence shortcut)
          This function creates a new action with the given icon, shortcut, and text.
 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)
          This convenience function creates a new action with the given text.
 QAction addAction(java.lang.String text, QSignalEmitter.AbstractSignal signal, QKeySequence shortcut)
          This convenience function creates a new action with the text text and specified 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. an action with QAction::isSeparator() returning true, and adds the new action to this menu's list of actions.
protected  void changeEvent(QEvent arg__1)
          

This event handler can be reimplemented to handle state changes.

 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.
protected  void enterEvent(QEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the arg__1 parameter.

 boolean event(QEvent arg__1)
          

This is the main event handler; it handles event arg__1.

 QAction exec()
          Executes this menu synchronously.
static QAction exec(java.util.List<QAction> actions, QPoint pos)
          Equivalent to exec(actions, pos, 0).
static QAction exec(java.util.List<QAction> actions, QPoint pos, QAction at)
          Executes this menu synchronously.
 QAction exec(QPoint pos)
          Equivalent to exec(pos, 0).
 QAction exec(QPoint pos, QAction at)
          Executes this menu synchronously.
protected  boolean focusNextPrevChild(boolean next)
          

Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't.

static QMenu fromNativePointer(QNativePointer nativePointer)
          This function returns the QMenu instance pointed to by nativePointer
protected  void hideEvent(QHideEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive widget hide events.

 void hideTearOffMenu()
          This function will forcibly hide the torn off menu making it disappear from the users desktop.
 QIcon icon()
          Returns 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. an action with QAction::isSeparator() returning true.
 boolean isEmpty()
          Returns true if there are no actions inserted into the menu, false otherwise.
 boolean isTearOffEnabled()
          Returns 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.
protected  void keyPressEvent(QKeyEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive key press events for the widget.

protected  void leaveEvent(QEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the arg__1 parameter.

 QAction menuAction()
          Returns the action associated with this menu.
protected  void mouseMoveEvent(QMouseEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget.

protected  void mousePressEvent(QMouseEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse press events for the widget.

protected  void mouseReleaseEvent(QMouseEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse release events for the widget.

protected  void paintEvent(QPaintEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter.

 void popup(QPoint pos)
          Equivalent to popup(pos, 0).
 void popup(QPoint pos, QAction at)
          Displays the menu so that the action at will be at the specified global position pos.
 boolean separatorsCollapsible()
          Returns 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 arg__1.
 void setIcon(QIcon icon)
          Sets The icon of the menu to icon.
 void setSeparatorsCollapsible(boolean collapse)
          Sets whether consecutive separators should be collapsed to collapse.
 void setTearOffEnabled(boolean arg__1)
          Sets whether the menu supports being torn off to arg__1.
 void setTitle(java.lang.String title)
          Sets The title of the menu to title.
 QSize sizeHint()
          

Returns the recommended size for the widget.

protected  void timerEvent(QTimerEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive timer events for the object.

 java.lang.String title()
          Returns The title of the menu.
protected  void wheelEvent(QWheelEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive wheel events for the widget.

 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensurePolished, focusInEvent, focusNextChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyReleaseEvent, layout, layoutDirection, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintEngine, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

aboutToHide

public final QSignalEmitter.Signal0 aboutToHide

This signal is emitted just before the menu is hidden from the user.

Compatible Slot Signature:
void mySlot()
See Also:
aboutToShow, hide


aboutToShow

public final QSignalEmitter.Signal0 aboutToShow

This signal is emitted just before the menu is shown to the user.

Compatible Slot Signature:
void mySlot()
See Also:
aboutToHide, show


hovered

public final QSignalEmitter.Signal1<QAction> hovered

This signal is emitted when a menu action is highlighted; action is the action that caused the signal to be emitted.

Often this is used to update status information.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QAction action)
void mySlot()
See Also:
triggered, QAction::hovered


triggered

public final QSignalEmitter.Signal1<QAction> triggered

This signal is emitted when an action in this menu is triggered; action is the action that caused the signal to be emitted.

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

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QAction action)
void mySlot()
See Also:
hovered, QAction::triggered

Constructor Detail

QMenu

public QMenu()

Equivalent to QMenu(0).


QMenu

public QMenu(QWidget parent)

Constructs a menu with parent 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).


QMenu

public QMenu(java.lang.String title)

Equivalent to QMenu(title, 0).


QMenu

public QMenu(java.lang.String title,
             QWidget parent)

Constructs a menu with a title and a 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).

See Also:
title
Method Detail

actionAt

public final QAction actionAt(QPoint arg__1)

Returns the item at arg__1; returns 0 if there is no item there.


actionGeometry

public final QRect actionGeometry(QAction arg__1)

Returns the geometry of action arg__1.


activeAction

public final QAction activeAction()

Returns the currently highlighted action, or 0 if no action is currently highlighted.

See Also:
setActiveAction

addAction

public final QAction addAction(QIcon icon,
                               java.lang.String text)

This convenience function creates a new action with an icon and some text. The function adds the newly created action to the menu's list of actions, and returns it.

See Also:
QWidget::addAction

addAction

public final QAction addAction(java.lang.String text)

This convenience function creates a new action with text. The function adds the newly created action to the menu's list of actions, and returns it.

See Also:
QWidget::addAction

addMenu

public final QAction addMenu(QMenu menu)

This convenience function adds menu as a submenu to this menu. It returns the menus menuAction.

See Also:
QWidget::addAction, QMenu::menuAction

addMenu

public final QMenu addMenu(java.lang.String title)

Appends a new QMenu with title to the menu. The menu takes ownership of the menu. Returns the new menu.

See Also:
QWidget::addAction, QMenu::menuAction

addMenu

public final QMenu addMenu(QIcon icon,
                           java.lang.String title)

Appends a new QMenu with icon and title to the menu. The menu takes ownership of the menu. Returns the new menu.

See Also:
QWidget::addAction, QMenu::menuAction

addSeparator

public final QAction addSeparator()

This convenience function creates a new separator action, i.e. an action with QAction::isSeparator() returning true, and adds the new action to this menu's list of actions. It returns the newly created action.

See Also:
QWidget::addAction

clear

public final void clear()

Removes all the menu's actions. Actions owned by the menu and not shown in any other widget are deleted.

See Also:
removeAction

columnCount

protected final int columnCount()

If a menu does not fit on the screen it lays itself out so that it does fit. It is style dependent what layout means (for example, on Windows it will use multiple columns).

This functions returns the number of columns necessary.


defaultAction

public final QAction defaultAction()

Returns the current default action.

See Also:
setDefaultAction

exec

public final QAction exec()

Executes this menu synchronously.

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());


exec

public final QAction exec(QPoint pos)

Equivalent to exec(pos, 0).


exec

public final QAction exec(QPoint pos,
                          QAction at)

Executes this menu synchronously.

Pops up the menu so that the action at will be at the specified global position pos. 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.

See Also:
popup, QWidget::mapToGlobal

hideTearOffMenu

public final void hideTearOffMenu()

This function will forcibly hide the torn off menu making it disappear from the users desktop.

See Also:
isTearOffMenuVisible, isTearOffEnabled

icon

public final QIcon icon()

Returns The icon of the menu.

This is equivalent to the QAction::icon property of the menuAction.

See Also:
setIcon

insertMenu

public final QAction insertMenu(QAction before,
                                QMenu menu)

This convenience function inserts menu before action before and returns the menus menuAction.

See Also:
QWidget::insertAction, addMenu

insertSeparator

public final QAction insertSeparator(QAction before)

This convenience function creates a new separator action, i.e. an action with QAction::isSeparator() returning true. The function inserts the newly created action into this menu's list of actions before action before and returns it.

See Also:
QWidget::insertAction, addSeparator

isEmpty

public final boolean isEmpty()

Returns true if there are no actions inserted into the menu, false otherwise.

See Also:
QWidget::actions

isTearOffEnabled

public final boolean isTearOffEnabled()

Returns whether the menu supports being torn off.

When true, 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.


isTearOffMenuVisible

public final boolean isTearOffMenuVisible()

When a menu is torn off a second menu is shown to display the menu contents in a new window. When the menu is in this mode and the menu is visible returns true; otherwise false.

See Also:
hideTearOffMenu, isTearOffEnabled

menuAction

public final QAction menuAction()

Returns the action associated with this menu.


popup

public final void popup(QPoint pos)

Equivalent to popup(pos, 0).


popup

public final void popup(QPoint pos,
                        QAction at)

Displays the menu so that the action at will be at the specified global position pos. To translate a widget's local coordinates into global coordinates, use 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.

See Also:
QWidget::mapToGlobal, exec

separatorsCollapsible

public final boolean separatorsCollapsible()

Returns whether consecutive separators should be collapsed.

This property specifies whether consecutive separators in the menu should be visually collapsed to a single one. Separators at the beginning or the end of the menu are also hidden.

See Also:
setSeparatorsCollapsible

setActiveAction

public final void setActiveAction(QAction act)

Sets the currently highlighted action to act.

See Also:
activeAction

setDefaultAction

public final void setDefaultAction(QAction arg__1)

This will set the default action to arg__1. The default action may have a visual queue depending on the current QStyle. A default action is usually meant to indicate what will defaultly happen on a drop, as shown in a context menu.

See Also:
defaultAction

setIcon

public final void setIcon(QIcon icon)

Sets The icon of the menu to icon.

This is equivalent to the QAction::icon property of the menuAction.

See Also:
icon

setSeparatorsCollapsible

public final void setSeparatorsCollapsible(boolean collapse)

Sets whether consecutive separators should be collapsed to collapse.

This property specifies whether consecutive separators in the menu should be visually collapsed to a single one. Separators at the beginning or the end of the menu are also hidden.

See Also:
separatorsCollapsible

setTearOffEnabled

public final void setTearOffEnabled(boolean arg__1)

Sets whether the menu supports being torn off to arg__1.

When true, 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.

See Also:
isTearOffEnabled

setTitle

public final void setTitle(java.lang.String title)

Sets The title of the menu to title.

This is equivalent to the QAction::text property of the menuAction.

See Also:
title

title

public final java.lang.String title()

Returns The title of the menu.

This is equivalent to the QAction::text property of the menuAction.

See Also:
setTitle

actionEvent

protected void actionEvent(QActionEvent arg__1)

This event handler is called with the given arg__1 whenever the widget's actions are changed.

Overrides:
actionEvent in class QWidget
See Also:
addAction, insertAction, removeAction, actions, QActionEvent

changeEvent

protected void changeEvent(QEvent arg__1)

This event handler can be reimplemented to handle state changes.

The state being changed in this event can be retrieved through event arg__1.

Change events include: QEvent::ToolBarChange, QEvent::ActivationChange, QEvent::EnabledChange, QEvent::FontChange, QEvent::StyleChange, QEvent::PaletteChange, QEvent::WindowTitleChange, QEvent::IconTextChange, QEvent::ModifiedChange, QEvent::MouseTrackingChange, QEvent::ParentChange, QEvent::WindowStateChange, QEvent::LanguageChange, QEvent::LocaleChange, QEvent::LayoutDirectionChange.

Overrides:
changeEvent in class QWidget

enterEvent

protected void enterEvent(QEvent arg__1)

This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the arg__1 parameter.

An event is sent to the widget when the mouse cursor enters the widget.

Overrides:
enterEvent in class QWidget
See Also:
leaveEvent, mouseMoveEvent, event

event

public boolean event(QEvent arg__1)

This is the main event handler; it handles event arg__1. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

Key press and release events are treated differently from other events. event checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event calls keyPressEvent.

Mouse and tablet event handling is also slightly special: only when the widget is enabled, event will call the specialized handlers such as mousePressEvent; otherwise it will discard the event.

This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.

Overrides:
event in class QWidget
See Also:
closeEvent, focusInEvent, focusOutEvent, enterEvent, keyPressEvent, keyReleaseEvent, leaveEvent, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveEvent, paintEvent, resizeEvent, QObject::event, QObject::timerEvent

focusNextPrevChild

protected boolean focusNextPrevChild(boolean next)

Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't.

If next is true, this function searches forward, if next is false, it searches backward.

Sometimes, you will want to reimplement this function. For example, a web browser might reimplement it to move its "current active link" forward or backward, and call focusNextPrevChild only when it reaches the last or first link on the "page".

Child widgets call focusNextPrevChild on their parent widgets, but only the window that contains the child widgets decides where to redirect focus. By reimplementing this function for an object, you thus gain control of focus traversal for all child widgets.

Overrides:
focusNextPrevChild in class QWidget
See Also:
focusNextChild, focusPreviousChild

hideEvent

protected void hideEvent(QHideEvent arg__1)

This event handler can be reimplemented in a subclass to receive widget hide events. The event is passed in the arg__1 parameter.

Hide events are sent to widgets immediately after they have been hidden.

Note: A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again. After receiving a spontaneous hide event, a widget is still considered visible in the sense of isVisible.

Overrides:
hideEvent in class QWidget
See Also:
visible, event, QHideEvent

keyPressEvent

protected void keyPressEvent(QKeyEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive key press events for the widget.

A widget must call setFocusPolicy to accept focus initially and have focus in order to receive a key press event.

If you reimplement this handler, it is very important that you ignore() the event if you do not understand it, so that the widget's parent can interpret it.

The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored.

Overrides:
keyPressEvent in class QWidget
See Also:
keyReleaseEvent, QKeyEvent::ignore, setFocusPolicy, focusInEvent, focusOutEvent, event, QKeyEvent, Tetrix Example

leaveEvent

protected void leaveEvent(QEvent arg__1)

This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the arg__1 parameter.

A leave event is sent to the widget when the mouse cursor leaves the widget.

Overrides:
leaveEvent in class QWidget
See Also:
enterEvent, mouseMoveEvent, event

mouseMoveEvent

protected void mouseMoveEvent(QMouseEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.

Overrides:
mouseMoveEvent in class QWidget
See Also:
setMouseTracking, mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, event, QMouseEvent, Example

mousePressEvent

protected void mousePressEvent(QMouseEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent the mouseReleaseEvent may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

Overrides:
mousePressEvent in class QWidget
See Also:
mouseReleaseEvent, mouseDoubleClickEvent, mouseMoveEvent, event, QMouseEvent, Example

mouseReleaseEvent

protected void mouseReleaseEvent(QMouseEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse release events for the widget.

Overrides:
mouseReleaseEvent in class QWidget
See Also:
mousePressEvent, mouseDoubleClickEvent, mouseMoveEvent, event, QMouseEvent, Example

paintEvent

protected void paintEvent(QPaintEvent arg__1)

This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint or update, or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint does not permit this optimization, so we suggest using update whenever possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.

The background can be set using setBackgroundRole and setPalette.

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent to avoid flicker.

Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:

    ...
    extern void qt_x11_set_global_double_buffer(bool);
    qt_x11_set_global_double_buffer(false);
    ...

Note: In general, one should refrain from calling update or repaint inside of paintEvent. For example, calling update or repaint on children inside a paintEvent results in undefined behavior; the child may or may not get a paint event.

Overrides:
paintEvent in class QWidget
See Also:
event, repaint, update, QPainter, QPixmap, QPaintEvent, Analog Clock Example

sizeHint

public QSize sizeHint()

Returns the recommended size for the widget.

If the value of this property is an invalid size, no size is recommended.

The default implementation of sizeHint returns an invalid size if there is no layout for this widget, and returns the layout's preferred size otherwise.

Overrides:
sizeHint in class QWidget
See Also:
QSize::isValid, minimumSizeHint, sizePolicy, setMinimumSize, updateGeometry

timerEvent

protected void timerEvent(QTimerEvent arg__1)

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the arg__1 parameter.

Overrides:
timerEvent in class QObject
See Also:
startTimer, killTimer, event

wheelEvent

protected void wheelEvent(QWheelEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive wheel events for the widget.

If you reimplement this handler, it is very important that you ignore() the event if you do not handle it, so that the widget's parent can interpret it.

The default implementation ignores the event.

Overrides:
wheelEvent in class QWidget
See Also:
QWheelEvent::ignore, QWheelEvent::accept, event, QWheelEvent

exec

public static QAction exec(java.util.List<QAction> actions,
                           QPoint pos)

Equivalent to exec(actions, pos, 0).


exec

public static QAction exec(java.util.List<QAction> actions,
                           QPoint pos,
                           QAction at)

Executes this menu synchronously.

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

See Also:
popup, QWidget::mapToGlobal

fromNativePointer

public static QMenu fromNativePointer(QNativePointer nativePointer)
This function returns the QMenu instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

initStyleOption

protected final void initStyleOption(QStyleOptionMenuItem option,
                                     QAction action)
Initialize option with the values from this menu and information from action. This method is useful for subclasses when they need a QStyleOptionMenuItem, but don't want to fill in all the information themselves.


addAction

public final 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. The action's QAction.triggered() signal is connected to the receiver's method slot. The function adds the newly created action to the menu's list of actions and returns it.


addAction

public final QAction addAction(java.lang.String text,
                               QSignalEmitter.AbstractSignal signal,
                               QKeySequence shortcut)
This convenience function creates a new action with the text text and specified shortcut. The action's QAction.triggered() signal is connected to the signal. The function adds the newly created action to the menu's list of actions and returns it.


addAction

public final 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. The action's QAction.triggered() signal is connected to the receiver's method slot. The function adds the newly created action to the menu's list of actions and returns it.


addAction

public final QAction addAction(java.lang.String text,
                               QSignalEmitter.AbstractSignal signal)
This convenience function creates a new action with the given text. It is connected to signal. text signal

Returns:

addAction

public final 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. It is connected to the receiver's method slot. It returns the created action.


addAction

public final QAction addAction(QIcon icon,
                               java.lang.String text,
                               QSignalEmitter.AbstractSignal signal,
                               QKeySequence shortcut)
This function creates a new action with the given icon, shortcut, and text. It is connected to signal. It returns the created action.


addAction

public final 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. It is connected to the receiver's method slot. It returns the created action.


addAction

public final QAction addAction(QIcon icon,
                               java.lang.String text,
                               QSignalEmitter.AbstractSignal signal)
This method creates an action with the given icon and text. It is connected to signal and returned.


Qt Jambi Home