1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QMenu Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QMenu Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus. <a href="#details">More...</a></p>
<p>Inherits <a href="qwidget.html">QWidget</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qmenu.html#QMenu">__init__</a></b> (<i>self</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qmenu.html#QMenu-2">__init__</a></b> (<i>self</i>, QString <i>title</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" />QAction <b><a href="qmenu.html#actionAt">actionAt</a></b> (<i>self</i>, QPoint)</li><li><div class="fn" /><b><a href="qmenu.html#actionEvent">actionEvent</a></b> (<i>self</i>, QActionEvent)</li><li><div class="fn" />QRect <b><a href="qmenu.html#actionGeometry">actionGeometry</a></b> (<i>self</i>, QAction)</li><li><div class="fn" />QAction <b><a href="qmenu.html#activeAction">activeAction</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qmenu.html#addAction">addAction</a></b> (<i>self</i>, QAction <i>action</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addAction-2">addAction</a></b> (<i>self</i>, QString <i>text</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addAction-3">addAction</a></b> (<i>self</i>, QIcon <i>icon</i>, QString <i>text</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addAction-4">addAction</a></b> (<i>self</i>, QString <i>text</i>, QObject <i>receiver</i>, SLOT() <i>member</i>, QKeySequence <i>shortcut</i> = 0)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addAction-5">addAction</a></b> (<i>self</i>, QString <i>text</i>, callable <i>receiver</i>, QKeySequence <i>shortcut</i> = 0)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addAction-6">addAction</a></b> (<i>self</i>, QIcon <i>icon</i>, QString <i>text</i>, QObject <i>receiver</i>, SLOT() <i>member</i>, QKeySequence <i>shortcut</i> = 0)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addAction-7">addAction</a></b> (<i>self</i>, QIcon <i>icon</i>, QString <i>text</i>, callable <i>receiver</i>, QKeySequence <i>shortcut</i> = 0)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addMenu">addMenu</a></b> (<i>self</i>, QMenu <i>menu</i>)</li><li><div class="fn" />QMenu <b><a href="qmenu.html#addMenu-2">addMenu</a></b> (<i>self</i>, QString <i>title</i>)</li><li><div class="fn" />QMenu <b><a href="qmenu.html#addMenu-3">addMenu</a></b> (<i>self</i>, QIcon <i>icon</i>, QString <i>title</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#addSeparator">addSeparator</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qmenu.html#changeEvent">changeEvent</a></b> (<i>self</i>, QEvent)</li><li><div class="fn" /><b><a href="qmenu.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qmenu.html#columnCount">columnCount</a></b> (<i>self</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#defaultAction">defaultAction</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qmenu.html#enterEvent">enterEvent</a></b> (<i>self</i>, QEvent)</li><li><div class="fn" />bool <b><a href="qmenu.html#event">event</a></b> (<i>self</i>, QEvent)</li><li><div class="fn" />QAction <b><a href="qmenu.html#exec">exec_</a></b> (<i>self</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#exec-2">exec_</a></b> (<i>self</i>, QPoint <i>pos</i>, QAction <i>at</i> = None)</li><li><div class="fn" /><b><a href="qmenu.html#hideEvent">hideEvent</a></b> (<i>self</i>, QHideEvent)</li><li><div class="fn" /><b><a href="qmenu.html#hideTearOffMenu">hideTearOffMenu</a></b> (<i>self</i>)</li><li><div class="fn" />QIcon <b><a href="qmenu.html#icon">icon</a></b> (<i>self</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#insertMenu">insertMenu</a></b> (<i>self</i>, QAction <i>before</i>, QMenu <i>menu</i>)</li><li><div class="fn" />QAction <b><a href="qmenu.html#insertSeparator">insertSeparator</a></b> (<i>self</i>, QAction <i>before</i>)</li><li><div class="fn" />bool <b><a href="qmenu.html#isTearOffEnabled">isTearOffEnabled</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qmenu.html#isTearOffMenuVisible">isTearOffMenuVisible</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qmenu.html#keyPressEvent">keyPressEvent</a></b> (<i>self</i>, QKeyEvent)</li><li><div class="fn" /><b><a href="qmenu.html#leaveEvent">leaveEvent</a></b> (<i>self</i>, QEvent)</li><li><div class="fn" />QAction <b><a href="qmenu.html#menuAction">menuAction</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qmenu.html#mouseMoveEvent">mouseMoveEvent</a></b> (<i>self</i>, QMouseEvent)</li><li><div class="fn" /><b><a href="qmenu.html#mousePressEvent">mousePressEvent</a></b> (<i>self</i>, QMouseEvent)</li><li><div class="fn" /><b><a href="qmenu.html#mouseReleaseEvent">mouseReleaseEvent</a></b> (<i>self</i>, QMouseEvent)</li><li><div class="fn" /><b><a href="qmenu.html#paintEvent">paintEvent</a></b> (<i>self</i>, QPaintEvent)</li><li><div class="fn" /><b><a href="qmenu.html#popup">popup</a></b> (<i>self</i>, QPoint <i>pos</i>, QAction <i>at</i> = None)</li><li><div class="fn" /><b><a href="qmenu.html#setActiveAction">setActiveAction</a></b> (<i>self</i>, QAction <i>act</i>)</li><li><div class="fn" /><b><a href="qmenu.html#setDefaultAction">setDefaultAction</a></b> (<i>self</i>, QAction)</li><li><div class="fn" /><b><a href="qmenu.html#setIcon">setIcon</a></b> (<i>self</i>, QIcon <i>icon</i>)</li><li><div class="fn" /><b><a href="qmenu.html#setNoReplayFor">setNoReplayFor</a></b> (<i>self</i>, QWidget <i>widget</i>)</li><li><div class="fn" /><b><a href="qmenu.html#setTearOffEnabled">setTearOffEnabled</a></b> (<i>self</i>, bool)</li><li><div class="fn" /><b><a href="qmenu.html#setTitle">setTitle</a></b> (<i>self</i>, QString <i>title</i>)</li><li><div class="fn" />QSize <b><a href="qmenu.html#sizeHint">sizeHint</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qmenu.html#timerEvent">timerEvent</a></b> (<i>self</i>, QTimerEvent)</li><li><div class="fn" />QString <b><a href="qmenu.html#title">title</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qmenu.html#wheelEvent">wheelEvent</a></b> (<i>self</i>, QWheelEvent)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QAction <b><a href="qmenu.html#exec-3">exec_</a></b> (QAction-list <i>actions</i>, QPoint <i>pos</i>, QAction <i>at</i> = None)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qmenu.html#aboutToShow">aboutToShow</a></b> ()</li><li><div class="fn" />void <b><a href="qmenu.html#hovered">hovered</a></b> (QAction *)</li><li><div class="fn" />void <b><a href="qmenu.html#triggered">triggered</a></b> (QAction *)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.</p>
<p>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 <a href="qmenubar.html#addMenu">QMenuBar.addMenu</a>() 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 <a href="qmenu.html#popup">popup</a>() or synchronously with <a href="qmenu.html#exec">exec_</a>(). Menus can also be invoked in response to button presses; these are just like context menus except for how they are invoked.</p>
<p>A menu consists of a list of action items. Actions are added with <a href="qmenu.html#addAction">addAction</a>(). An action is represented vertically and rendered by <a href="qstyle.html">QStyle</a>. 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".</p>
<p>There are three kinds of action items: separators, actions that show a submenu, and actions that perform an action. Separators are inserted with <a href="qmenu.html#addSeparator">addSeparator</a>(). For submenus use <a href="qmenu.html#addMenu">addMenu</a>(). All other items are considered action items.</p>
<p>When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is <a href="qaction.html#triggered">triggered()</a>. In addition, QMenu provides two signals, <a href="qmenu-qt3.html#activated">activated</a>() and <a href="qmenu-qt3.html#highlighted">highlighted</a>(), which signal the <a href="qaction.html">QAction</a> that was triggered from the menu.</p>
<p>You clear a menu with <a href="qmenu.html#clear">clear</a>() and remove individual action items with <a href="qwidget.html#removeAction">removeAction</a>().</p>
<p>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 <a href="qmenu.html#tearOffEnabled-prop">setTearOffEnabled</a>(). 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 <a href="qtoolbar.html">QToolBar</a> instead.</p>
<p>See the <a href="mainwindows-menus.html">Menus Example</a> for an example of how to use <a href="qmenubar.html">QMenuBar</a> and QMenu in your application.</p>
<p>Important inherited functions: <a href="qmenu.html#addAction">addAction</a>(), <a href="qwidget.html#removeAction">removeAction</a>(), <a href="qmenu.html#clear">clear</a>(), <a href="qmenu.html#addSeparator">addSeparator</a>(), and <a href="qmenu.html#addMenu">addMenu</a>().</p>
<p>See also <a href="qmenubar.html">QMenuBar</a> and <a href="guibooks.html#fowler">GUI Design Handbook: Menu, Drop-Down and Pop-Up</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QMenu" />QMenu.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a menu with parent <i>parent</i>.</p>
<p>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 <a href="qobject.html">QObject</a>).</p>
<h3 class="fn"><a name="QMenu-2" />QMenu.__init__ (<i>self</i>, <a href="qstring.html">QString</a> <i>title</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a menu with a <i>title</i> and a <i>parent</i>.</p>
<p>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 <a href="qobject.html">QObject</a>).</p>
<p>See also <a href="qmenu.html#title-prop">title</a>.</p>
<h3 class="fn"><a name="actionAt" /><a href="qaction.html">QAction</a> QMenu.actionAt (<i>self</i>, <a href="qpoint.html">QPoint</a>)</h3><p>Returns the item at <i>pt</i>; returns 0 if there is no item there.</p>
<h3 class="fn"><a name="actionEvent" />QMenu.actionEvent (<i>self</i>, <a href="qactionevent.html">QActionEvent</a>)</h3><h3 class="fn"><a name="actionGeometry" /><a href="qrect.html">QRect</a> QMenu.actionGeometry (<i>self</i>, <a href="qaction.html">QAction</a>)</h3><p>Returns the geometry of action <i>act</i>.</p>
<h3 class="fn"><a name="activeAction" /><a href="qaction.html">QAction</a> QMenu.activeAction (<i>self</i>)</h3><p>Returns the currently highlighted action, or 0 if no action is currently highlighted.</p>
<p>See also <a href="qmenu.html#setActiveAction">setActiveAction</a>().</p>
<h3 class="fn"><a name="addAction" />QMenu.addAction (<i>self</i>, <a href="qaction.html">QAction</a> <i>action</i>)</h3><p>This convenience function creates a new action with <i>text</i>. The function adds the newly created action to the menu's list of actions, and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>().</p>
<h3 class="fn"><a name="addAction-2" /><a href="qaction.html">QAction</a> QMenu.addAction (<i>self</i>, <a href="qstring.html">QString</a> <i>text</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>This convenience function creates a new action with an <i>icon</i> and some <i>text</i>. The function adds the newly created action to the menu's list of actions, and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>().</p>
<h3 class="fn"><a name="addAction-3" /><a href="qaction.html">QAction</a> QMenu.addAction (<i>self</i>, <a href="qicon.html">QIcon</a> <i>icon</i>, <a href="qstring.html">QString</a> <i>text</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>This convenience function creates a new action with the text <i>text</i> and an optional shortcut <i>shortcut</i>. The action's <a href="qaction.html#triggered">triggered()</a> signal is connected to the <i>receiver</i>'s <i>member</i> slot. The function adds the newly created action to the menu's list of actions and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>().</p>
<h3 class="fn"><a name="addAction-4" /><a href="qaction.html">QAction</a> QMenu.addAction (<i>self</i>, <a href="qstring.html">QString</a> <i>text</i>, <a href="qobject.html">QObject</a> <i>receiver</i>, SLOT() <i>member</i>, <a href="qkeysequence.html">QKeySequence</a> <i>shortcut</i> = 0)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>This convenience function creates a new action with an <i>icon</i> and some <i>text</i> and an optional shortcut <i>shortcut</i>. The action's <a href="qaction.html#triggered">triggered()</a> signal is connected to the <i>member</i> slot of the <i>receiver</i> object. The function adds the newly created action to the menu's list of actions, and returns it.</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>().</p>
<h3 class="fn"><a name="addAction-5" /><a href="qaction.html">QAction</a> QMenu.addAction (<i>self</i>, <a href="qstring.html">QString</a> <i>text</i>, callable <i>receiver</i>, <a href="qkeysequence.html">QKeySequence</a> <i>shortcut</i> = 0)</h3><h3 class="fn"><a name="addAction-6" /><a href="qaction.html">QAction</a> QMenu.addAction (<i>self</i>, <a href="qicon.html">QIcon</a> <i>icon</i>, <a href="qstring.html">QString</a> <i>text</i>, <a href="qobject.html">QObject</a> <i>receiver</i>, SLOT() <i>member</i>, <a href="qkeysequence.html">QKeySequence</a> <i>shortcut</i> = 0)</h3><h3 class="fn"><a name="addAction-7" /><a href="qaction.html">QAction</a> QMenu.addAction (<i>self</i>, <a href="qicon.html">QIcon</a> <i>icon</i>, <a href="qstring.html">QString</a> <i>text</i>, callable <i>receiver</i>, <a href="qkeysequence.html">QKeySequence</a> <i>shortcut</i> = 0)</h3><h3 class="fn"><a name="addMenu" /><a href="qaction.html">QAction</a> QMenu.addMenu (<i>self</i>, <a href="qmenu.html">QMenu</a> <i>menu</i>)</h3><p>This convenience function adds <i>menu</i> as a submenu to this menu. It returns the menus <a href="qmenu.html#menuAction">menuAction</a>().</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>() and <a href="qmenu.html#menuAction">QMenu.menuAction</a>().</p>
<h3 class="fn"><a name="addMenu-2" /><a href="qmenu.html">QMenu</a> QMenu.addMenu (<i>self</i>, <a href="qstring.html">QString</a> <i>title</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Appends a new <a href="qmenu.html">QMenu</a> with <i>title</i> to the menu. The menu takes ownership of the menu. Returns the new menu.</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>() and <a href="qmenu.html#menuAction">QMenu.menuAction</a>().</p>
<h3 class="fn"><a name="addMenu-3" /><a href="qmenu.html">QMenu</a> QMenu.addMenu (<i>self</i>, <a href="qicon.html">QIcon</a> <i>icon</i>, <a href="qstring.html">QString</a> <i>title</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Appends a new <a href="qmenu.html">QMenu</a> with <i>icon</i> and <i>title</i> to the menu. The menu takes ownership of the menu. Returns the new menu.</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>() and <a href="qmenu.html#menuAction">QMenu.menuAction</a>().</p>
<h3 class="fn"><a name="addSeparator" /><a href="qaction.html">QAction</a> QMenu.addSeparator (<i>self</i>)</h3><p>This convenience function creates a new separator action, i.e. an action with <a href="qaction.html#isSeparator">QAction.isSeparator</a>() returning true, and adds the new action to this menu's list of actions. It returns the newly created action.</p>
<p>See also <a href="qwidget.html#addAction">QWidget.addAction</a>().</p>
<h3 class="fn"><a name="changeEvent" />QMenu.changeEvent (<i>self</i>, <a href="qevent.html">QEvent</a>)</h3><h3 class="fn"><a name="clear" />QMenu.clear (<i>self</i>)</h3><p>Removes all the menu's actions. Actions owned by the menu and not shown in any other widget are deleted.</p>
<p>See also <a href="qwidget.html#removeAction">removeAction</a>().</p>
<h3 class="fn"><a name="columnCount" />int QMenu.columnCount (<i>self</i>)</h3><p>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).</p>
<p>This functions returns the number of columns necessary.</p>
<h3 class="fn"><a name="defaultAction" /><a href="qaction.html">QAction</a> QMenu.defaultAction (<i>self</i>)</h3><p>Returns the current default action.</p>
<p>See also <a href="qmenu.html#setDefaultAction">setDefaultAction</a>().</p>
<h3 class="fn"><a name="enterEvent" />QMenu.enterEvent (<i>self</i>, <a href="qevent.html">QEvent</a>)</h3><h3 class="fn"><a name="event" />bool QMenu.event (<i>self</i>, <a href="qevent.html">QEvent</a>)</h3><h3 class="fn"><a name="exec" /><a href="qaction.html">QAction</a> QMenu.exec_ (<i>self</i>)</h3><p>Executes this menu synchronously.</p>
<p>This is equivalent to <tt>exec(pos())</tt>.</p>
<p>This returns the triggered <a href="qaction.html">QAction</a> in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).</p>
<p>In most situations you'll want to specify the position yourself, for example, the current mouse position:</p>
<pre>
exec(QCursor.pos());
</pre>
<p>or aligned to a widget:</p>
<pre>
exec(somewidget.mapToGlobal(QPoint(0,0)));
</pre>
<p>or in reaction to a <a href="qmouseevent.html">QMouseEvent</a> *e:</p>
<pre>
exec(e->globalPos());
</pre>
<h3 class="fn"><a name="exec-2" /><a href="qaction.html">QAction</a> QMenu.exec_ (<i>self</i>, <a href="qpoint.html">QPoint</a> <i>pos</i>, <a href="qaction.html">QAction</a> <i>at</i> = None)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Executes this menu synchronously.</p>
<p>Pops up the menu so that the action <i>action</i> will be at the specified <i>global</i> position <i>p</i>. To translate a widget's local coordinates into global coordinates, use <a href="qwidget.html#mapToGlobal">QWidget.mapToGlobal</a>().</p>
<p>This returns the triggered <a href="qaction.html">QAction</a> in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).</p>
<p>Note that all signals are emitted as usual. If you connect a <a href="qaction.html">QAction</a> to a slot and call the menu's <a href="qmenu.html#exec">exec_</a>(), you get the result both via the signal-slot connection and in the return value of <a href="qmenu.html#exec">exec_</a>().</p>
<p>Common usage is to position the menu at the current mouse position:</p>
<pre>
exec(QCursor.pos());
</pre>
<p>or aligned to a widget:</p>
<pre>
exec(somewidget.mapToGlobal(QPoint(0, 0)));
</pre>
<p>or in reaction to a <a href="qmouseevent.html">QMouseEvent</a> *e:</p>
<pre>
exec(e->globalPos());
</pre>
<p>When positioning a menu with <a href="qmenu.html#exec">exec_</a>() or <a href="qmenu.html#popup">popup</a>(), bear in mind that you cannot rely on the menu's current <a href="qwidget.html#size-prop">size</a>(). 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 <a href="qwidget.html#sizeHint-prop">sizeHint</a>() which calculates the proper size depending on the menu's current contents.</p>
<p>See also <a href="qmenu.html#popup">popup</a>() and <a href="qwidget.html#mapToGlobal">QWidget.mapToGlobal</a>().</p>
<h3 class="fn"><a name="exec-3" /><a href="qaction.html">QAction</a> QMenu.exec_ (QAction-list <i>actions</i>, <a href="qpoint.html">QPoint</a> <i>pos</i>, <a href="qaction.html">QAction</a> <i>at</i> = None)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Executes this menu synchronously.</p>
<p>The menu's actions are specified by the list of <i>actions</i>. The menu will pop up so that the specified action, <i>at</i>, appears at global position <i>pos</i>. If <i>at</i> is not specified then the menu appears at position <i>pos</i>.</p>
<p>The function returns the triggered <a href="qaction.html">QAction</a> in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).</p>
<p>This is equivalent to:</p>
<pre>
QMenu menu;
QAction *at = actions[0]; // Assumes actions is not empty
foreach (QAction *a, actions)
menu.addAction(a);
menu.exec(pos, at);
</pre>
<p>See also <a href="qmenu.html#popup">popup</a>() and <a href="qwidget.html#mapToGlobal">QWidget.mapToGlobal</a>().</p>
<h3 class="fn"><a name="hideEvent" />QMenu.hideEvent (<i>self</i>, <a href="qhideevent.html">QHideEvent</a>)</h3><h3 class="fn"><a name="hideTearOffMenu" />QMenu.hideTearOffMenu (<i>self</i>)</h3><p>This function will forcibly hide the torn off menu making it disappear from the users desktop.</p>
<p>See also <a href="qmenu.html#isTearOffMenuVisible">isTearOffMenuVisible</a>() and <a href="qmenu.html#tearOffEnabled-prop">isTearOffEnabled</a>().</p>
<h3 class="fn"><a name="icon" /><a href="qicon.html">QIcon</a> QMenu.icon (<i>self</i>)</h3><h3 class="fn"><a name="insertMenu" /><a href="qaction.html">QAction</a> QMenu.insertMenu (<i>self</i>, <a href="qaction.html">QAction</a> <i>before</i>, <a href="qmenu.html">QMenu</a> <i>menu</i>)</h3><p>This convenience function inserts <i>menu</i> before action <i>before</i> and returns the menus <a href="qmenu.html#menuAction">menuAction</a>().</p>
<p>See also <a href="qwidget.html#insertAction">QWidget.insertAction</a>() and <a href="qmenu.html#addMenu">addMenu</a>().</p>
<h3 class="fn"><a name="insertSeparator" /><a href="qaction.html">QAction</a> QMenu.insertSeparator (<i>self</i>, <a href="qaction.html">QAction</a> <i>before</i>)</h3><p>This convenience function creates a new separator action, i.e. an action with <a href="qaction.html#isSeparator">QAction.isSeparator</a>() returning true. The function inserts the newly created action into this menu's list of actions before action <i>before</i> and returns it.</p>
<p>See also <a href="qwidget.html#insertAction">QWidget.insertAction</a>() and <a href="qmenu.html#addSeparator">addSeparator</a>().</p>
<h3 class="fn"><a name="isTearOffEnabled" />bool QMenu.isTearOffEnabled (<i>self</i>)</h3><h3 class="fn"><a name="isTearOffMenuVisible" />bool QMenu.isTearOffMenuVisible (<i>self</i>)</h3><p>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.</p>
<p>See also <a href="qmenu.html#hideTearOffMenu">hideTearOffMenu</a>() and <a href="qmenu.html#tearOffEnabled-prop">isTearOffEnabled</a>().</p>
<h3 class="fn"><a name="keyPressEvent" />QMenu.keyPressEvent (<i>self</i>, <a href="qkeyevent.html">QKeyEvent</a>)</h3><h3 class="fn"><a name="leaveEvent" />QMenu.leaveEvent (<i>self</i>, <a href="qevent.html">QEvent</a>)</h3><h3 class="fn"><a name="menuAction" /><a href="qaction.html">QAction</a> QMenu.menuAction (<i>self</i>)</h3><p>Returns the action associated with this menu.</p>
<h3 class="fn"><a name="mouseMoveEvent" />QMenu.mouseMoveEvent (<i>self</i>, <a href="qmouseevent.html">QMouseEvent</a>)</h3><h3 class="fn"><a name="mousePressEvent" />QMenu.mousePressEvent (<i>self</i>, <a href="qmouseevent.html">QMouseEvent</a>)</h3><h3 class="fn"><a name="mouseReleaseEvent" />QMenu.mouseReleaseEvent (<i>self</i>, <a href="qmouseevent.html">QMouseEvent</a>)</h3><h3 class="fn"><a name="paintEvent" />QMenu.paintEvent (<i>self</i>, <a href="qpaintevent.html">QPaintEvent</a>)</h3><h3 class="fn"><a name="popup" />QMenu.popup (<i>self</i>, <a href="qpoint.html">QPoint</a> <i>pos</i>, <a href="qaction.html">QAction</a> <i>at</i> = None)</h3><p>Displays the menu so that the action <i>atAction</i> will be at the specified <i>global</i> position <i>p</i>. To translate a widget's local coordinates into global coordinates, use <a href="qwidget.html#mapToGlobal">QWidget.mapToGlobal</a>().</p>
<p>When positioning a menu with <a href="qmenu.html#exec">exec_</a>() or popup(), bear in mind that you cannot rely on the menu's current <a href="qwidget.html#size-prop">size</a>(). 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 <a href="qwidget.html#sizeHint-prop">sizeHint</a>() which calculates the proper size depending on the menu's current contents.</p>
<p>See also <a href="qwidget.html#mapToGlobal">QWidget.mapToGlobal</a>() and <a href="qmenu.html#exec">exec_</a>().</p>
<h3 class="fn"><a name="setActiveAction" />QMenu.setActiveAction (<i>self</i>, <a href="qaction.html">QAction</a> <i>act</i>)</h3><p>Sets the currently highlighted action to <i>act</i>.</p>
<p>See also <a href="qmenu.html#activeAction">activeAction</a>().</p>
<h3 class="fn"><a name="setDefaultAction" />QMenu.setDefaultAction (<i>self</i>, <a href="qaction.html">QAction</a>)</h3><p>This will set the default action to <i>act</i>. The default action may have a visual queue depending on the current <a href="qstyle.html">QStyle</a>. A default action is usually meant to indicate what will defaultly happen on a drop, as shown in a context menu.</p>
<p>See also <a href="qmenu.html#defaultAction">defaultAction</a>().</p>
<h3 class="fn"><a name="setIcon" />QMenu.setIcon (<i>self</i>, <a href="qicon.html">QIcon</a> <i>icon</i>)</h3><h3 class="fn"><a name="setNoReplayFor" />QMenu.setNoReplayFor (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>widget</i>)</h3><h3 class="fn"><a name="setTearOffEnabled" />QMenu.setTearOffEnabled (<i>self</i>, bool)</h3><h3 class="fn"><a name="setTitle" />QMenu.setTitle (<i>self</i>, <a href="qstring.html">QString</a> <i>title</i>)</h3><h3 class="fn"><a name="sizeHint" /><a href="qsize.html">QSize</a> QMenu.sizeHint (<i>self</i>)</h3><h3 class="fn"><a name="timerEvent" />QMenu.timerEvent (<i>self</i>, <a href="qtimerevent.html">QTimerEvent</a>)</h3><h3 class="fn"><a name="title" /><a href="qstring.html">QString</a> QMenu.title (<i>self</i>)</h3><h3 class="fn"><a name="wheelEvent" />QMenu.wheelEvent (<i>self</i>, <a href="qwheelevent.html">QWheelEvent</a>)</h3><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="aboutToShow" />void aboutToShow ()</h3><p>This signal is emitted just before the menu is shown to the user.</p>
<h3 class="fn"><a name="hovered" />void hovered (QAction *)</h3><p>This signal is emitted when a menu action is highlighted; <i>action</i> is the action that caused the signal to be emitted.</p>
<p>Often this is used to update status information.</p>
<p>See also <a href="qmenu.html#triggered">triggered</a>() and <a href="qaction.html#hovered">QAction.hovered</a>().</p>
<h3 class="fn"><a name="triggered" />void triggered (QAction *)</h3><p>This signal is emitted when a menu action is triggered; <i>action</i> is the action that caused the signal to be emitted.</p>
<p>Normally, you connect each menu action's <a href="qaction.html#triggered">triggered()</a> 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".</p>
<p>See also <a href="qmenu.html#hovered">hovered</a>() and <a href="qaction.html#triggered">QAction.triggered</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt 4.0.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.trolltech.com">Trolltech AS</a> 2006</td><td align="right" width="25%">Qt 4.1.4</td></tr></table></div></address></body></html>
|