qpopupmenu.html

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

HTML
781
字号
<p> <p>See also <a href="#aboutToShow">aboutToShow</a>(), <a href="qmenudata.html#setItemEnabled">setItemEnabled</a>(), <a href="qmenudata.html#setItemChecked">setItemChecked</a>(), <a href="qmenudata.html#insertItem">insertItem</a>() and <a href="qmenudata.html#removeItem">removeItem</a>().<h3 class=fn>void <a name="aboutToShow"></a>QPopupMenu::aboutToShow ()<tt> [signal]</tt></h3> <p> This signal is emitted just before the popup menu is displayed.  Youcan connect it to any slot that sets up the menu contents (e.g. toensure that the right items are enabled).<p> <p>See also <a href="#aboutToHide">aboutToHide</a>(), <a href="qmenudata.html#setItemEnabled">setItemEnabled</a>(), <a href="qmenudata.html#setItemChecked">setItemChecked</a>(), <a href="qmenudata.html#insertItem">insertItem</a>() and <a href="qmenudata.html#removeItem">removeItem</a>().<p>Example: <a href="mdi-example.html#x2031">mdi/application.cpp</a>.<h3 class=fn><a href="qkeysequence.html">QKeySequence</a> <a name="accel"></a>QMenuData::accel ( int&nbsp;id ) const</h3>Returns the accelerator key that has been defined for the menu item <em>id</em>,or 0 if it has no accelerator key.<p> <p>See also <a href="qmenudata.html#setAccel">setAccel</a>(), <a href="qaccel.html">QAccel</a> and <a href="qnamespace-h.html">qnamespace.h</a>.<h3 class=fn>void <a name="activated"></a>QPopupMenu::activated ( int&nbsp;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 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>Examples: <a href="grapher-nsplugin-example.html#x2775">grapher/grapher.cpp</a>, <a href="helpviewer-example.html#x1006">helpviewer/helpwindow.cpp</a>, <a href="qdir-example.html#x1828">qdir/qdir.cpp</a>, <a href="qwerty-example.html#x384">qwerty/qwerty.cpp</a>, <a href="scrollview-example.html#x729">scrollview/scrollview.cpp</a> and <a href="showimg-example.html#x1279">showimg/showimg.cpp</a>.<h3 class=fn>void <a name="changeItem"></a>QMenuData::changeItem ( int&nbsp;id, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text )</h3>Changes the text of the menu item <em>id</em> to <em>text</em>. If the item hasan icon, the icon remains unchanged.<p>See also <a href="qmenudata.html#text">text</a>().<h3 class=fn>void <a name="changeItem-2"></a>QMenuData::changeItem ( int&nbsp;id, const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Changes the pixmap of the menu item <em>id</em> to the pixmap<em>pixmap</em>. If the item has an icon, the icon is unchanged.<p>See also <a href="qmenudata.html#pixmap">pixmap</a>().<h3 class=fn>void <a name="changeItem-3"></a>QMenuData::changeItem ( int&nbsp;id, const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Changes the iconset and text of the menu item <em>id</em>to the <em>icon</em> and <em>text</em> respectively.<p>See also <a href="qmenudata.html#pixmap">pixmap</a>().<h3 class=fn>void <a name="changeItem-4"></a>QMenuData::changeItem ( int&nbsp;id, const&nbsp;<a href="qiconset.html">QIconSet</a>&nbsp;&amp;&nbsp;icon, const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Changes the iconset and pixmap of the menu item <em>id</em>to <em>icon</em> and <em>pixmap</em> respectively.<p>See also <a href="qmenudata.html#pixmap">pixmap</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>int <a name="columns"></a>QPopupMenu::columns () const<tt> [protected]</tt></h3>If a popup menu does not fit on the screen it lays itself out so that itdoes fit, it is style dependant what layout means (ie on Windows it willuse multiple columns).<p> This functions returns the number of columns necessary.<p> <p>See also <a href="qwidget.html#sizeHint-prop">sizeHint</a>.<h3 class=fn>bool <a name="connectItem"></a>QMenuData::connectItem ( int&nbsp;id, const&nbsp;<a href="qobject.html">QObject</a>&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member )</h3>Connects the menu item with identifier <em>id</em> to <em>receiver</em>'s<em>member</em> slot or signal.<p> The receiver's slot/signal is activated when the menu item is activated.<p> <p>See also <a href="qmenudata.html#disconnectItem">disconnectItem</a>() and <a href="qmenudata.html#setItemParameter">setItemParameter</a>().<p>Example: <a href="menu-example.html#x1859">menu/menu.cpp</a>.<h3 class=fn>bool <a name="disconnectItem"></a>QMenuData::disconnectItem ( int&nbsp;id, const&nbsp;<a href="qobject.html">QObject</a>&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member )</h3>Disconnects the <em>receiver</em>'s <em>member</em> from the menu item withidentifier <em>id</em>.<p> All connections are removed when the menu data object is destroyed.<p> <p>See also <a href="qmenudata.html#connectItem">connectItem</a>() and <a href="qmenudata.html#setItemParameter">setItemParameter</a>().<h3 class=fn>void <a name="drawContents"></a>QPopupMenu::drawContents ( <a href="qpainter.html">QPainter</a>&nbsp;*&nbsp;p )<tt> [virtual protected]</tt></h3>Draws all menu items using painter <em>p</em>.<p>Reimplemented from <a href="qframe.html#drawContents">QFrame</a>.<h3 class=fn>void <a name="drawItem"></a>QPopupMenu::drawItem ( <a href="qpainter.html">QPainter</a>&nbsp;*&nbsp;p, int&nbsp;tab_, QMenuItem&nbsp;*&nbsp;mi, bool&nbsp;act, int&nbsp;x, int&nbsp;y, int&nbsp;w, int&nbsp;h )<tt> [protected]</tt></h3>Draws menu item <em>mi</em> in the area <em>x</em>, <em>y</em>, <em>w</em>, <em>h</em>,using painter <em>p</em>.  The item is drawn active if <em>act</em> is TRUE ordrawn inactive if <em>act</em> is FALSE. The rightmost <em>tab_</em> pixels areused for accelerator text.<p> <p>See also <a href="qstyle.html#drawControl">QStyle::drawControl</a>().<h3 class=fn>int <a name="exec"></a>QPopupMenu::exec ()</h3>  Executes this popup synchronously.<p> This is equivalent to <tt>exec(mapToGlobal(QPoint(0,0)))</tt>.In most situations you'll want to specify the position yourself,for example at the current mouse position:<pre>      <a href="#exec">exec</a>(QCursor::<a href="qcursor.html#pos">pos</a>());  </pre> or aligned to a widget:<pre>      <a href="#exec">exec</a>(somewidget.mapToGlobal(QPoint(0,0)));  </pre> <p>Examples: <a href="fileiconview-example.html#x862">fileiconview/qfileiconview.cpp</a> and <a href="scribble-example.html#x944">scribble/scribble.cpp</a>.<h3 class=fn>int <a name="exec-2"></a>QPopupMenu::exec ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;pos, int&nbsp;indexAtPoint = 0 )</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Executes this popup synchronously.<p> Opens the popup menu so that the item number <em>indexAtPoint</em> will beat the specified <em>global</em> position <em>pos</em>.  To translate a widget'slocal coordinates into global coordinates, use <a href="qwidget.html#mapToGlobal">QWidget::mapToGlobal</a>().<p> The return code is the id of the selected item in either the popupmenu or one of its submenus, or -1 if no item is selected (normallybecause the user presses Escape).<p> Note that all signals are emitted as usual.  If you connect a menuitem to a slot and call the menu's <a href="#exec">exec</a>(), you get the result bothvia the signal-slot connection and in the return value of exec().<p> Common usage is to position the popup at the currentmouse position:<pre>      <a href="#exec">exec</a>(QCursor::<a href="qcursor.html#pos">pos</a>());  </pre> or aligned to a widget:<pre>      <a href="#exec">exec</a>(somewidget.mapToGlobal(QPoint(0,0)));  </pre> <p> When positioning a popup with exec() or <a href="#popup">popup</a>(), bear in mind thatyou cannot rely on the popup menu's current <a href="qwidget.html#size">size</a>(). For performancereasons, the popup adapts its size only when necessary. So in manycases, the size before and after the show is different. Instead, use<a href="qwidget.html#sizeHint">sizeHint</a>(). It calculates the proper size depending on the menu'scurrent contents.<p> <p>See also <a href="#popup">popup</a>() and <a href="qwidget.html#sizeHint-prop">sizeHint</a>.<h3 class=fn>void <a name="highlighted"></a>QPopupMenu::highlighted ( int&nbsp;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> <p>See also <a href="#activated">activated</a>() and <a href="qmenudata.html#insertItem">QMenuData::insertItem</a>().<h3 class=fn><a href="qiconset.html">QIconSet</a>&nbsp;* <a name="iconSet"></a>QMenuData::iconSet ( int&nbsp;id ) const</h3>Returns the icon set that has been set for menu item <em>id</em>, or 0 if no iconset has been set.<p>See also <a href="qmenudata.html#changeItem">changeItem</a>(), <a href="qmenudata.html#text">text</a>() and <a href="qmenudata.html#pixmap">pixmap</a>().<h3 class=fn>int <a name="idAt"></a>QPopupMenu::idAt ( int&nbsp;index ) const</h3><p> Returns the identifier of the menu item at position <em>index</em> in the internallist, or -1 if <em>index</em> is out of range.<p> <p>See also <a href="qmenudata.html#setId">QMenuData::setId</a>() and <a href="qmenudata.html#indexOf">QMenuData::indexOf</a>().<p>Example: <a href="scrollview-example.html#x730">scrollview/scrollview.cpp</a>.<h3 class=fn>int <a name="idAt-2"></a>QPopupMenu::idAt ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;pos ) const</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns the id of the item at <em>pos</em>, or -1 if there is no itemthere or if it is a separator item.<h3 class=fn>int <a name="insertItem"></a>QMenuData::insertItem ( 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>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>    <a href="qmenubar.html">QMenuBar</a>   *mainMenu = new <a href="qmenubar.html">QMenuBar</a>;    QPopupMenu *fileMenu = new QPopupMenu;    fileMenu-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "New",  myView, SLOT(newFile()), CTRL+Key_N );    fileMenu-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Open", myView, SLOT(open()),    CTRL+Key_O );    mainMenu-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "File", fileMenu );  </pre> 

⌨️ 快捷键说明

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