📄 qmenubar.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/widgets/qmenubar.cpp:72 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QMenuBar Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QMenuBar Class Reference</h1><p>The QMenuBar class provides a horizontal menu bar.<a href="#details">More...</a><p><tt>#include <<a href="qmenubar-h.html">qmenubar.h</a>></tt><p>Inherits <a href="qframe.html">QFrame</a> and <a href="qmenudata.html">QMenuData</a>.<p><a href="qmenubar-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QMenuBar"><b>QMenuBar</b></a> ( QWidget * parent = 0, const char * name = 0 )</div></li><li><div class=fn><a href="#~QMenuBar"><b>~QMenuBar</b></a> ()</div></li><li><div class=fn>virtual void <a href="#show"><b>show</b></a> ()</div></li><li><div class=fn>virtual void <a href="#hide"><b>hide</b></a> ()</div></li><li><div class=fn>virtual int <a href="#heightForWidth"><b>heightForWidth</b></a> ( int max_width ) const</div></li><li><div class=fn>enum <a href="#Separator-enum"><b>Separator</b></a> { Never = 0, InWindowsStyle = 1 }</div></li><li><div class=fn>Separator separator () const <em>(obsolete)</em></div></li><li><div class=fn>virtual void setSeparator ( Separator when ) <em>(obsolete)</em></div></li><li><div class=fn>void <a href="#setDefaultUp"><b>setDefaultUp</b></a> ( bool )</div></li><li><div class=fn>bool <a href="#isDefaultUp"><b>isDefaultUp</b></a> () const</div></li></ul><h2>Signals</h2><ul><li><div class=fn>void <a href="#activated"><b>activated</b></a> ( int id )</div></li><li><div class=fn>void <a href="#highlighted"><b>highlighted</b></a> ( int id )</div></li></ul><h2>Important Inherited Members</h2><ul><li><div class=fn>int <a href="#insertItem"><b>insertItem</b></a> ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-2"><b>insertItem</b></a> ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-3"><b>insertItem</b></a> ( const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-4"><b>insertItem</b></a> ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-5"><b>insertItem</b></a> ( const QString & text, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-6"><b>insertItem</b></a> ( const QIconSet & icon, const QString & text, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-7"><b>insertItem</b></a> ( const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-8"><b>insertItem</b></a> ( const QIconSet & icon, const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-9"><b>insertItem</b></a> ( const QPixmap & pixmap, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-a"><b>insertItem</b></a> ( const QIconSet & icon, const QPixmap & pixmap, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-b"><b>insertItem</b></a> ( const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-c"><b>insertItem</b></a> ( const QIconSet & icon, const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-d"><b>insertItem</b></a> ( QWidget * widget, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-e"><b>insertItem</b></a> ( const QIconSet & icon, QCustomMenuItem * custom, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertItem-f"><b>insertItem</b></a> ( QCustomMenuItem * custom, int id = -1, int index = -1 )</div></li><li><div class=fn>int <a href="#insertSeparator"><b>insertSeparator</b></a> ( int index = -1 )</div></li><li><div class=fn>void <a href="#removeItem"><b>removeItem</b></a> ( int id )</div></li><li><div class=fn>void <a href="#clear"><b>clear</b></a> ()</div></li><li><div class=fn>bool <a href="#isItemEnabled"><b>isItemEnabled</b></a> ( int id ) const</div></li><li><div class=fn>void <a href="#setItemEnabled"><b>setItemEnabled</b></a> ( int id, bool enable )</div></li></ul><h2>Properties</h2><ul><li><div class=fn>bool <a href="#defaultUp-prop"><b>defaultUp</b></a> - the popup orientation</div></li><li><div class=fn>Separator separator - in which cases a menubar sparator is drawn <em>(obsolete)</em></div></li></ul><h2>Protected Members</h2><ul><li><div class=fn>virtual void <a href="#drawContents"><b>drawContents</b></a> ( QPainter * p )</div></li><li><div class=fn>virtual void <a href="#menuContentsChanged"><b>menuContentsChanged</b></a> ()</div></li><li><div class=fn>virtual void <a href="#menuStateChanged"><b>menuStateChanged</b></a> ()</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QMenuBar class provides a horizontal menu bar.<p> <p> A menu bar consists of a list of pull-down menu items.You add menu items with <a href="qmenudata.html#insertItem">insertItem()</a>. For example, asuming that <tt>menubar</tt> is apointer to a QMenuBar and <tt>filemenu</tt> is a pointer to a<a href="qpopupmenu.html">QPopupMenu</a>, the following statement inserts the menu intothe menu bar:<pre> menubar->insertItem( "&File", filemenu ); </pre> The ampersand in the menuitem's text sets Alt+F as a shortcut for this menu. (You can use"&&" to get a real ampersand in the menu bar.)<p> Items are either enabled or disabled. You toggle their state with<a href="qmenudata.html#setItemEnabled">setItemEnabled</a>().<p> There is no need to lay out a menu bar. It automatically sets itsown geometry to the top of the parent widget and changes itappropriately whenever the parent is resized.<p> <p> Example of creating a menu bar with menu items (from <a href="menu-example.html">menu/menu.cpp</a>):<pre> <a href="qpopupmenu.html">QPopupMenu</a> *file = new <a href="qpopupmenu.html">QPopupMenu</a>( this );</pre><pre> file-><a href="qmenudata.html#insertItem">insertItem</a>( p1, "&Open", this, SLOT(open()), CTRL+Key_O ); file-><a href="qmenudata.html#insertItem">insertItem</a>( p2, "&New", this, SLOT(news()), CTRL+Key_N );</pre><pre> menu = new QMenuBar( this );</pre><pre> menu-><a href="qmenudata.html#insertItem">insertItem</a>( "&File", file );</pre><p> In most main window style applications you would use the menuBar()provided in <a href="qmainwindow.html">QMainWindow</a>, adding <a href="qpopupmenu.html">QPopupMenu</a>s to the menu barand adding <a href="qaction.html">QAction</a>s to the popup menus.<p> Example (from <a href="qaction-application-example.html">action/application.cpp</a>):<pre> <a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>( this ); <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&File", file ); fileNewAction-><a href="qaction.html#addTo">addTo</a>( file );</pre><p> Menu items can have text and pixmaps (or iconsets), see thevarious <a href="qmenudata.html#insertItem">insertItem()</a>overloads, as well as separators, see <a href="qmenudata.html#insertSeparator">insertSeparator()</a>. You canalso add custom menu items that are derived from<a href="qcustommenuitem.html">QCustomMenuItem</a>.<p> Menu items may be removed with <a href="qmenudata.html#removeItem">removeItem</a>() and enabled or disabledwith <a href="qmenudata.html#setItemEnabled">setItemEnabled()</a>.<p> <img src=qmenubar-m.png> <img src=qmenubar-w.png><p> QMenuBar on Qt/Mac is a wrapper for using the system-widemenubar. However, if you have multiple menubars in one dialog theoutermost menubar (normally inside a widget with <a href="qt.html#WidgetFlags-enum">WType_TopLevel</a>) will be used for the global menubar.<p> Qt/Mac also provides a menubar merging feature, with this yourQMenubar will be brought closer to conforming to accepted Mac OS Xmenubar layout. The merging functionality is based on stringmatching the title of a <a href="qpopupmenu.html">QPopupMenu</a> entry, these strings aretranslated (using <a href="qobject.html#tr">QObject::tr</a>()) in the "QMenuBar" context. If anentry is moved the regularly connected slots will still fire as ifit was in the original place. The table below outlines the stringslooked for and where the entry is placed if matched:<p> <center><table cellpadding="4" cellspacing="2" border="0"><tr bgcolor="#a2c511"> <th valign="top">String matches <th valign="top">Placement <th valign="top">Notes<tr bgcolor="#f0f0f0"> <td valign="top">about.* <td valign="top">Application Menu | About <application name><td valign="top">If this entry is not found no About item will appear in the Application Menu<tr bgcolor="#d0d0d0"> <td valign="top">config, options, setup, settings, preferences <td valign="top">Application Menu | Settings<td valign="top">If this entry is not found the Settings item will be disabled<tr bgcolor="#f0f0f0"> <td valign="top">quit, exit <td valign="top">Application Menu | Quit <application name><td valign="top">If this entry is not found a default Quit item will be created to call<a href="qapplication.html#quit">QApplication::quit</a>()</table></center><p> <p>See also <a href="qpopupmenu.html">QPopupMenu</a>, <a href="qaccel.html">QAccel</a>, <a href="qaction.html">QAction</a>, <a href="http://developer.apple.com/techpubs/macosx/Carbon/HumanInterfaceToolbox/Aqua/aqua.html">Aqua Style Guidelines</a>, <a href="guibooks.html#fowler">GUI Design Handbook: Menu Bar</a> and <a href="application.html">Main Window and Related Classes</a>.<hr><h2>Member Type Documentation</h2><h3 class=fn><a name="Separator-enum"></a>QMenuBar::Separator</h3> <p> This enum type is used to decide whether QMenuBar should draw aseparator line at its bottom. The possible values are:<ul><li><tt>QMenuBar::Never</tt> - In many applications there is already a separator,and having two looks wrong.<li><tt>QMenuBar::InWindowsStyle</tt> - In some other applications a separatorlooks good in Windows style, but nowhere else.</ul><p> <hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QMenuBar"></a>QMenuBar::QMenuBar ( <a href="qwidget.html">QWidget</a> * parent = 0, const char * name = 0 )</h3>Constructs a menu bar with a <em>parent</em> and a <em>name</em>.<h3 class=fn><a name="~QMenuBar"></a>QMenuBar::~QMenuBar ()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -