📄 qmenubar.html
字号:
</h3>Destroys the menu bar.<h3 class=fn>void <a name="activated"></a>QMenuBar::activated ( int id )<tt> [signal]</tt></h3><p> This signal is emitted when a menu item is selected; <em>id</em> is the idof the selected item.<p> Normally you will connect each menu item to a single slot using<a href="qmenudata.html#insertItem">QMenuData::insertItem</a>(), but sometimes you will want to connectseveral items to a single slot (most often if the user selects froman array). This signal is useful in such cases.<p> <p>See also <a href="#highlighted">highlighted</a>() and <a href="qmenudata.html#insertItem">QMenuData::insertItem</a>().<p>Example: <a href="progress-example.html#x35">progress/progress.cpp</a>.<h3 class=fn>void <a name="clear"></a>QMenuData::clear ()</h3>Removes all menu items.<p> <p>See also <a href="qmenudata.html#removeItem">removeItem</a>() and <a href="qmenudata.html#removeItemAt">removeItemAt</a>().<p>Examples: <a href="mdi-example.html#x2012">mdi/application.cpp</a> and <a href="qwerty-example.html#x368">qwerty/qwerty.cpp</a>.<h3 class=fn>void <a name="drawContents"></a>QMenuBar::drawContents ( <a href="qpainter.html">QPainter</a> * p )<tt> [virtual protected]</tt></h3>Called from <a href="qframe.html#paintEvent">QFrame::paintEvent</a>().Draws the menu bar contents using painter <em>p</em>.<p>Reimplemented from <a href="qframe.html#drawContents">QFrame</a>.<h3 class=fn>int <a name="heightForWidth"></a>QMenuBar::heightForWidth ( int max_width ) const<tt> [virtual]</tt></h3>Returns the height that the menu would resize itself to if its parent(and hence itself) resized to the given <em>max_width</em>. This can beuseful for simple layout tasks in which the height of the menu baris needed after items have been inserted. See<a href="showimg-example.html">showimg/showimg.cpp</a> for an example of the usage.<p>Example: <a href="showimg-example.html#x1263">showimg/showimg.cpp</a>.<p>Reimplemented from <a href="qwidget.html#heightForWidth">QWidget</a>.<h3 class=fn>void <a name="hide"></a>QMenuBar::hide ()<tt> [virtual]</tt></h3>Reimplements <a href="qwidget.html#hide">QWidget::hide</a>() in order to deselect any selected item, andcalls setUpLayout() for the main window.<p>Example: <a href="grapher-nsplugin-example.html#x2753">grapher/grapher.cpp</a>.<p>Reimplemented from <a href="qwidget.html#hide">QWidget</a>.<h3 class=fn>void <a name="highlighted"></a>QMenuBar::highlighted ( int id )<tt> [signal]</tt></h3><p> This signal is emitted when a menu item is highlighted; <em>id</em> is theid of the highlighted item.<p> Normally, you will connect each menu item to a single slot using<a href="qmenudata.html#insertItem">QMenuData::insertItem</a>(), but sometimes you will want to connectseveral items to a single slot (most often if the user selects froman array). This signal is useful in such cases.<p> <p>See also <a href="#activated">activated</a>() and <a href="qmenudata.html#insertItem">QMenuData::insertItem</a>().<h3 class=fn>int <a name="insertItem"></a>QMenuData::insertItem ( const <a href="qstring.html">QString</a> & text, const <a href="qobject.html">QObject</a> * receiver, const char * member, const <a href="qkeysequence.html">QKeySequence</a> & accel = 0, int id = -1, int index = -1 )</h3>The family of <a href="qmenudata.html#insertItem">insertItem</a>() functions inserts menu items into apopup menu or a menu bar.<p> A menu item is usually either a text string or a pixmap, both withan optional icon or keyboard accelerator. For special cases it isalso possible to insert custom items (see <a href="qcustommenuitem.html">QCustomMenuItem</a>) or evenwidgets into popup menus.<p> Some insertItem() members take a popup menu as an additionalargument. Use this to insert submenus to existing menus or pulldownmenus to a menu bar.<p> The number of insert functions may look confusing, but they are actuallyquite simple to use.<p> This default version inserts a menu item with the text <em>text</em>, theaccelerator key <em>accel</em>, an id and an optional index and connectsit to the slot <em>member</em> in the object <em>receiver</em>.<p> Example:<pre> QMenuBar *mainMenu = new QMenuBar; <a href="qpopupmenu.html">QPopupMenu</a> *fileMenu = new <a href="qpopupmenu.html">QPopupMenu</a>; fileMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "New", myView, SLOT(newFile()), CTRL+Key_N ); fileMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "Open", myView, SLOT(open()), CTRL+Key_O ); mainMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "File", fileMenu ); </pre> <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->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 <a href="qpopupmenu.html">QPopupMenu</a> 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 <a href="qiconset.html">QIconSet</a> & icon, const <a href="qstring.html">QString</a> & text, const <a href="qobject.html">QObject</a> * receiver, const char * member, const <a href="qkeysequence.html">QKeySequence</a> & accel = 0, int id = -1, int 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 <a href="qpixmap.html">QPixmap</a> & pixmap, const <a href="qobject.html">QObject</a> * receiver, const char * member, const <a href="qkeysequence.html">QKeySequence</a> & accel = 0, int id = -1, int 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 <a href="qiconset.html">QIconSet</a> & icon, const <a href="qpixmap.html">QPixmap</a> & pixmap, const <a href="qobject.html">QObject</a> * receiver, const char * member, const <a href="qkeysequence.html">QKeySequence</a> & accel = 0, int id = -1, int 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 <a href="qstring.html">QString</a> & text, int id = -1, int 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 <a href="qiconset.html">QIconSet</a> & icon, const <a href="qstring.html">QString</a> & text, int id = -1, int 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 <a href="qstring.html">QString</a> & text, <a href="qpopupmenu.html">QPopupMenu</a> * popup, int id = -1, int 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 <a href="qiconset.html">QIconSet</a> & icon, const <a href="qstring.html">QString</a> & text, <a href="qpopupmenu.html">QPopupMenu</a> * popup, int id = -1, int 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 <a href="qpixmap.html">QPixmap</a> & pixmap, int id = -1, int 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>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -