qpopupmenu.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 781 行 · 第 1/4 页

HTML
781
字号
<p> Not all insert functions take an object/slot parameter or anaccelerator key. Use <a href="qmenudata.html#connectItem">connectItem</a>() and <a href="qmenudata.html#setAccel">setAccel</a>() on these items.<p> If you need to translate accelerators, use <a href="qobject.html#tr">tr</a>() with a stringdescription that use pass to the <a href="qkeysequence.html">QKeySequence</a> constructor:<pre>    fileMenu-&gt;insertItem( <a href="qobject.html#tr">tr</a>("Open"), myView, SLOT(open()),                         <a href="qobject.html#tr">tr</a>("Ctrl+O") );  </pre> <p> In the example above, pressing Ctrl+N or selecting "Open" from themenu activates the myView->open() function.<p> Some insert functions take a <a href="qiconset.html">QIconSet</a> parameter to specify thelittle menu item icon. Note that you can always pass a <a href="qpixmap.html">QPixmap</a>object instead.<p> The <em>index</em> specifies the position in the menu.  The menu item isappended at the end of the list if <em>index</em> is negative.<p> Note that keyboard accelerators in Qt are not application-global,instead they are bound to a certain top-level window. For example,accelerators in QPopupMenu items only work for menus that areassociated with a certain window. This is true for popup menus thatlive in a menu bar since their accelerators will then be installedin the menu bar itself. This also applies to stand-alone popup menusthat have a top-level widget in their <a href="qwidget.html#parentWidget">parentWidget</a>() chain. The menuwill then install its accelerator object on that top-level widget.For all other cases use an independent <a href="qaccel.html">QAccel</a> object.<p> <b>Warning:</b> Be careful when passing a literal 0 to <a href="qmenudata.html#insertItem">insertItem</a>() becausesome C++ compilers choose the wrong overloaded function.Cast the 0 to what you mean, e.g. <tt>(QObject*)0</tt>.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>(), <a href="qmenudata.html#connectItem">connectItem</a>(), <a href="qaccel.html">QAccel</a> and <a href="qnamespace-h.html">qnamespace.h</a>.<p>Examples: <a href="addressbook-example.html#x518">addressbook/mainwindow.cpp</a>, <a href="canvas-example.html#x2712">canvas/canvas.cpp</a>, <a href="mdi-example.html#x2013">mdi/application.cpp</a>, <a href="menu-example.html#x1860">menu/menu.cpp</a>, <a href="qwerty-example.html#x369">qwerty/qwerty.cpp</a>, <a href="scrollview-example.html#x721">scrollview/scrollview.cpp</a> and <a href="showimg-example.html#x1265">showimg/showimg.cpp</a>.<h3 class=fn>int <a name="insertItem-2"></a>QMenuData::insertItem ( const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text, const&nbsp;<a href="qobject.html">QObject</a>&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member, const&nbsp;<a href="qkeysequence.html">QKeySequence</a>&nbsp;&amp;&nbsp;accel = 0, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with icon <em>icon</em>, text <em>text</em>,accelerator <em>accel</em>, optional id <em>id</em>, and optional <em>index</em>. Themenu item is connected it to the <em>receiver</em>'s <em>member</em> slot. Theicon will be displayed to the left of the text in the item.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>(), <a href="qmenudata.html#connectItem">connectItem</a>(), <a href="qaccel.html">QAccel</a> and <a href="qnamespace-h.html">qnamespace.h</a>.<h3 class=fn>int <a name="insertItem-3"></a>QMenuData::insertItem ( const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap, const&nbsp;<a href="qobject.html">QObject</a>&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member, const&nbsp;<a href="qkeysequence.html">QKeySequence</a>&nbsp;&amp;&nbsp;accel = 0, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with pixmap <em>pixmap</em>, accelerator <em>accel</em>, optional id <em>id</em>, and optional <em>index</em>. The menu item isconnected it to the <em>receiver</em>'s <em>member</em> slot. The icon will bedisplayed to the left of the text in the item.<p> To look best when being highlighted as a menu item, the pixmap shouldprovide a mask (see <a href="qpixmap.html#mask">QPixmap::mask</a>()).<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-4"></a>QMenuData::insertItem ( const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap, const&nbsp;<a href="qobject.html">QObject</a>&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member, const&nbsp;<a href="qkeysequence.html">QKeySequence</a>&nbsp;&amp;&nbsp;accel = 0, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with icon <em>icon</em>, pixmap <em>pixmap</em>,accelerator <em>accel</em>, optional id <em>id</em>, and optional <em>index</em>.The icon will be displayed to the left of the pixmap in the item.The item is connected to the <em>member</em> slot in the <em>receiver</em> object.<p> To look best when being highlighted as a menu item, the pixmap shouldprovide a mask (see <a href="qpixmap.html#mask">QPixmap::mask</a>()).<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>(), <a href="qmenudata.html#connectItem">connectItem</a>(), <a href="qaccel.html">QAccel</a> and <a href="qnamespace-h.html">qnamespace.h</a>.<h3 class=fn>int <a name="insertItem-5"></a>QMenuData::insertItem ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with text <em>text</em>, optional id <em>id</em>, andoptional <em>index</em>.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-6"></a>QMenuData::insertItem ( const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with icon <em>icon</em>, text <em>text</em>,optional id <em>id</em>, and optional <em>index</em>.The icon will be displayed to the left of the text in the item.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-7"></a>QMenuData::insertItem ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text, <a href="qpopupmenu.html">QPopupMenu</a>&nbsp;*&nbsp;popup, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with text <em>text</em>, submenu <em>popup</em>,optional id <em>id</em>, and optional <em>index</em>.<p> The <em>popup</em> must be deleted by the programmer or by its parentwidget.  It is not deleted when this menu item is removed or whenthe menu is deleted.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-8"></a>QMenuData::insertItem ( const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text, <a href="qpopupmenu.html">QPopupMenu</a>&nbsp;*&nbsp;popup, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with icon <em>icon</em>, text <em>text</em>,submenu <em>popup</em>, optional id <em>id</em>, and optional <em>index</em>.The icon will be displayed to the left of the text in the item.<p> The <em>popup</em> must be deleted by the programmer or by its parentwidget.  It is not deleted when this menu item is removed or whenthe menu is deleted.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-9"></a>QMenuData::insertItem ( const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with pixmap <em>pixmap</em>, optional id <em>id</em>, and optional <em>index</em>.<p> To look best when being highlighted as a menu item, the pixmap shouldprovide a mask (see <a href="qpixmap.html#mask">QPixmap::mask</a>()).<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-a"></a>QMenuData::insertItem ( const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with icon <em>icon</em>, pixmap <em>pixmap</em>,optional id <em>id</em>, and optional <em>index</em>.The icon will be displayed to the left of the pixmap in the item.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-b"></a>QMenuData::insertItem ( const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap, <a href="qpopupmenu.html">QPopupMenu</a>&nbsp;*&nbsp;popup, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with pixmap <em>pixmap</em>, submenu <em>popup</em>,optional id <em>id</em>, and optional <em>index</em>.<p> The <em>popup</em> must be deleted by the programmer or by its parentwidget.  It is not deleted when this menu item is removed or whenthe menu is deleted.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-c"></a>QMenuData::insertItem ( const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap, <a href="qpopupmenu.html">QPopupMenu</a>&nbsp;*&nbsp;popup, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item with icon <em>icon</em>, pixmap <em>pixmap</em>submenu <em>popup</em>, optional id <em>id</em>, and optional <em>index</em>.The icon will be displayed to the left of the pixmap in the item.<p> The <em>popup</em> must be deleted by the programmer or by its parentwidget.  It is not deleted when this menu item is removed or whenthe menu is deleted.<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>(), <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#setAccel">setAccel</a>() and <a href="qmenudata.html#connectItem">connectItem</a>().<h3 class=fn>int <a name="insertItem-d"></a>QMenuData::insertItem ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;widget, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a menu item that consists of the widget <em>widget</em> withoptional id <em>id</em>, and optional <em>index</em>.<p> Ownership of <em>widget</em> is transferred to the popup menu or to themenu bar.<p> Theoretically, any widget can be inserted into a popup menu. Inpractice, this only makes sense with certain widgets.<p> If a widget is not focus-enabled (see <a href="qwidget.html#isFocusEnabled">QWidget::isFocusEnabled</a>()),the menu treats it as a separator; this means that the item is notselectable and will never get focus. In this way you can, for example,simply insert a <a href="qlabel.html">QLabel</a> if you need a popup menu with a title.<p> If the widget is focus-enabled it will get focus when the usertraverses the popup menu with the arrow keys. If the widget does notaccept ArrowUp and ArrowDown in its key event handler, the focuswill move back to the menu when the respective arrow key is hitone more time. This works with a <a href="qlineedit.html">QLineEdit</a>, for example.  If thewidget accepts the arrow key itself, it must also provide thepossibility to put the focus back on the menu again by calling<a href="qwidget.html#focusNextPrevChild">QWidget::focusNextPrevChild</a>(). Futhermore, if theembedded widget closes the menu when the user made a selection, thiscan be done safely by calling<pre>    if ( <a href="qwidget.html#isVisible">isVisible</a>() &amp;&amp;         <a href="qwidget.html#parentWidget">parentWidget</a>() &amp;&amp;         <a href="qwidget.html#parentWidget">parentWidget</a>()-&gt;inherits("QPopupMenu") )        <a href="qwidget.html#parentWidget">parentWidget</a>()-&gt;close();  </pre> <p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>().<h3 class=fn>int <a name="insertItem-e"></a>QMenuData::insertItem ( const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, <a href="qcustommenuitem.html">QCustomMenuItem</a>&nbsp;*&nbsp;custom, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a custom menu item <em>custom</em> with an <em>icon</em> and withoptional id <em>id</em>, and optional <em>index</em>.<p> This only works with popup menus. It is not supported for menu bars.Ownership of <em>custom</em> is transferred to the popup menu.<p> If you want to connect a custom item to a certain slot, use <a href="qmenudata.html#connectItem">connectItem</a>().<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#connectItem">connectItem</a>(), <a href="qmenudata.html#removeItem">removeItem</a>() and <a href="qcustommenuitem.html">QCustomMenuItem</a>.<h3 class=fn>int <a name="insertItem-f"></a>QMenuData::insertItem ( <a href="qcustommenuitem.html">QCustomMenuItem</a>&nbsp;*&nbsp;custom, int&nbsp;id = -1, int&nbsp;index = -1 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Inserts a custom menu item <em>custom</em> withoptional id <em>id</em>, and optional <em>index</em>.<p> This only works with popup menus. It is not supported for menu bars.Ownership of <em>custom</em> is transferred to the popup menu.<p> If you want to connect a custom item to a certain slot, use <a href="qmenudata.html#connectItem">connectItem</a>().<p> Returns the allocated <a href="qmenudata.html#menu-identifier">menu identifier</a> number (<em>id</em> if <em>id</em> >= 0).<p> <p>See also <a href="qmenudata.html#connectItem">connectItem</a>(), <a href="qmenudata.html#removeItem">removeItem</a>() and <a href="qcustommenuitem.html">QCustomMenuItem</a>.<h3 class=fn>int <a name="insertSeparator"></a>QMenuData::insertSeparator ( int&nbsp;index = -1 )</h3>Inserts a separator at position <em>index</em>.The separator becomes the last menu item if <em>index</em> is negative.<p> In a popup menu a separator is rendered as a horizontal line.  In aMotif menu bar a separator is spacing, so the rest of the items(normally just "Help") are drawn right-justified.  In a Windowsmenu bar separators are ignored (to comply with the Windows styleguidelines).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?