📄 qmenubar.3qt
字号:
'\" t.TH QMenuBar 3qt "11 October 2001" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQMenuBar \- Horizontal menu bar.PP\fC#include <qmenubar.h>\fR.PPInherits QFrame and QMenuData..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQMenuBar\fR ( QWidget * parent = 0, const char * name = 0 )".br.ti -1c.BI "\fB~QMenuBar\fR ()".br.ti -1c.BI "virtual void \fBshow\fR ()".br.ti -1c.BI "virtual void \fBhide\fR ()".br.ti -1c.BI "virtual int \fBheightForWidth\fR ( int max_width ) const".br.ti -1c.BI "enum \fBSeparator\fR { Never = 0, InWindowsStyle = 1 }".br.ti -1c.BI "Separator separator () const \fI(obsolete)\fR".br.ti -1c.BI "virtual void setSeparator ( Separator when ) \fI(obsolete)\fR".br.ti -1c.BI "void \fBsetDefaultUp\fR ( bool )".br.ti -1c.BI "bool \fBisDefaultUp\fR () const".br.in -1c.SS "Signals".in +1c.ti -1c.BI "void \fBactivated\fR ( int id )".br.ti -1c.BI "void \fBhighlighted\fR ( int id )".br.in -1c.SS "Important Inherited Members".in +1c.ti -1c.BI "int \fBinsertItem\fR ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QString & text, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QIconSet & icon, const QString & text, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QIconSet & icon, const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QPixmap & pixmap, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QIconSet & icon, const QPixmap & pixmap, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QIconSet & icon, const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( QWidget * widget, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( const QIconSet & icon, QCustomMenuItem * custom, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertItem\fR ( QCustomMenuItem * custom, int id = -1, int index = -1 )".br.ti -1c.BI "int \fBinsertSeparator\fR ( int index = -1 )".br.ti -1c.BI "void \fBremoveItem\fR ( int id )".br.ti -1c.BI "void \fBclear\fR ()".br.ti -1c.BI "bool \fBisItemEnabled\fR ( int id ) const".br.ti -1c.BI "void \fBsetItemEnabled\fR ( int id, bool enable )".br.in -1c.SS "Properties".in +1c.ti -1c.BI "bool \fBdefaultUp\fR - the popup orientation".br.ti -1c.BI "Separator separator - in which cases a menubar sparator is drawn \fI(obsolete)\fR".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBdrawContents\fR ( QPainter * p )".br.ti -1c.BI "virtual void \fBmenuContentsChanged\fR ()".br.ti -1c.BI "virtual void \fBmenuStateChanged\fR ()".br.in -1c.SH DESCRIPTIONThe QMenuBar class provides a horizontal menu bar..PPA menu bar consists of a list of pull-down menu items. You add menu items with insertItem(). For example, asuming that \fCmenubar\fR is a pointer to a QMenuBar and \fCfilemenu\fR is a pointer to a QPopupMenu, the following statement inserts the menu into the menu bar:.PP.nf.br menubar->insertItem( "&File", filemenu );.br.fiThe ampersand in the menu item's text sets Alt+F as a shortcut for this menu. (You can use" &&" to get a real ampersand in the menu bar.).PPItems are either enabled or disabled. You toggle their state with setItemEnabled()..PPThere is no need to lay out a menu bar. It automatically sets its own geometry to the top of the parent widget and changes it appropriately whenever the parent is resized..PPExample of creating a menu bar with menu items (from menu/menu.cpp):.PP.nf.br QPopupMenu *file = new QPopupMenu( this );.fi.PP.nf.br file->insertItem( p1, "&Open", this, SLOT(open()), CTRL+Key_O );.br file->insertItem( p2, "&New", this, SLOT(news()), CTRL+Key_N );.fi.PP.nf.br menu = new QMenuBar( this );.fi.PP.nf.br menu->insertItem( "&File", file );.fi.PPIn most main window style applications you would use the menuBar() provided in QMainWindow, adding QPopupMenus to the menu bar and adding QActions to the popup menus..PPExample (from action/application.cpp):.PP.nf.br QPopupMenu * file = new QPopupMenu( this );.br menuBar()->insertItem( "&File", file );.br fileNewAction->addTo( file );.fi.PPMenu items can have text and pixmaps (or iconsets), see the various insertItem() overloads, as well as separators, see insertSeparator(). You can also add custom menu items that are derived from QCustomMenuItem..PPMenu items may be removed with removeItem() and enabled or disabled with setItemEnabled()..PPQMenuBar on Qt/Mac is a wrapper for using the system-wide menubar. However if you have multiple menubars in one dialog the outermost menubar (normally inside a widget with WType_TopLevel) will be used for the global menubar..PP.ce 1.B "[Image Omitted]".PP.ce 1.B "[Image Omitted]".PPSee also QPopupMenu, QAccel, QAction, GUI Design Handbook: Menu Bar and Main Window and Related Classes..SS "Member Type Documentation".SH "QMenuBar::Separator"This enum type is used to decide whether QMenuBar should draw a separator line at its bottom. The possible values are:.TP\fCQMenuBar::Never\fR - In many applications there is already a separator, and having two looks wrong..TP\fCQMenuBar::InWindowsStyle\fR - In some other applications a separator looks good in Windows style, but nowhere else..PP.SH MEMBER FUNCTION DOCUMENTATION.SH "QMenuBar::QMenuBar ( QWidget * parent = 0, const char * name = 0 )"Constructs a menu bar with a \fIparent\fR and a \fIname\fR..SH "QMenuBar::~QMenuBar ()"Destroys the menu bar..SH "void QMenuBar::activated ( int id )\fC [signal]\fR"This signal is emitted when a menu item is selected; \fIid\fR is the id of the selected item..PPNormally you will connect each menu item to a single slot using QMenuData::insertItem(), but sometimes you will want to connect several items to a single slot (most often if the user selects from an array). This signal is useful in such cases..PPSee also highlighted() and QMenuData::insertItem()..PPExample: progress/progress.cpp..SH "void QMenuData::clear ()"Removes all menu items..PPSee also removeItem() and removeItemAt()..PPExamples:.)l mdi/application.cpp and qwerty/qwerty.cpp..SH "void QMenuBar::drawContents ( QPainter * p )\fC [virtual protected]\fR"Called from QFrame::paintEvent(). Draws the menu bar contents using painter \fIp\fR..PPReimplemented from QFrame..SH "int QMenuBar::heightForWidth ( int max_width ) const\fC [virtual]\fR"Returns the height that the menu would resize itself to if its parent (and hence itself) resized to the given \fImax_width\fR. This can be useful for simple layout tasks in which the height of the menu bar is needed after items have been inserted. See showimg/showimg.cpp for an example of the usage..PPExample: showimg/showimg.cpp..PPReimplemented from QWidget..SH "void QMenuBar::hide ()\fC [virtual]\fR"Reimplements QWidget::hide() in order to deselect any selected item, and calls setUpLayout() for the main window..PPExample: grapher/grapher.cpp..PPReimplemented from QWidget..SH "void QMenuBar::highlighted ( int id )\fC [signal]\fR"This signal is emitted when a menu item is highlighted; \fIid\fR is the id of the highlighted item..PPNormally, you will connect each menu item to a single slot using QMenuData::insertItem(), but sometimes you will want to connect several items to a single slot (most often if the user selects from an array). This signal is useful in such cases..PPSee also activated() and QMenuData::insertItem()..SH "int QMenuData::insertItem ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"The family of insertItem() functions inserts menu items into a popup menu or a menu bar..PPA menu item is usually either a text string or a pixmap, both with an optional icon or keyboard accelerator. For special cases it is also possible to insert custom items (see QCustomMenuItem) or even widgets into popup menus..PPSome insertItem() members take a popup menu as an additional argument. Use this to insert submenus to existing menus or pulldown menus to a menu bar..PPThe number of insert functions may look confusing, but they are actually quite simple to use..PPThis default version inserts a menu item with the text \fItext\fR, the accelerator key \fIaccel\fR, an id and an optional index and connects it to the slot \fImember\fR in the object \fIreceiver\fR..PPExample:.PP.nf.br QMenuBar *mainMenu = new QMenuBar;.br QPopupMenu *fileMenu = new QPopupMenu;.br fileMenu->insertItem( "New", myView, SLOT(newFile()), CTRL+Key_N );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -