📄 qmenudata.3qt
字号:
.br fileMenu->insertItem( tr("Open"), myView, SLOT(open()),.br QAccel::stringToKey( tr("Ctrl+O") ) );.fi.PPIn the example above, pressing CTRL+N or selecting "open" from the menu activates the myView->open() function..PPSome insert functions take a QIconSet parameter to specify the little menu item icon. Note that you can always pass a QPixmap object instead..PPThe menu item is assigned the identifier \fIid\fR or an automatically generated identifier if \fIid\fR is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application..PPThe \fIindex\fR specifies the position in the menu. The menu item is appended at the end of the list if \fIindex\fR is negative..PPNote that keyboard accelerators in Qt are not application global, but bound to a certain toplevel window. Accelerators in QPopupMenu items therefore only work for menus that are associated with a certain window. This is true for popup menus that live in a menu bar, for instance. In that case, the accelerator will be installed on the menu bar itself. It also works for stand-alone popup menus that have a toplevel widget in their parentWidget()- chain. The menu will then install its accelerator object on that toplevel widget. For all other cases, use an independent QAccel object..PP\fBWarning:\fR Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. \fC(QObject*)0\fR..PPSee also removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h..SH "int QMenuData::insertItem ( QCustomMenuItem * custom, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a custom menu item \fIcustom.\fR.PPThis only works with popup menus. It is not supported for menu bars. Ownership of \fIcustom\fR is transferred to the popup menu..PPIf you want to connect a custom item to a certain slot, use connectItem()..PPSee also connectItem(), removeItem() and QCustomMenuItem..SH "int QMenuData::insertItem ( QWidget * widget, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item that consists of the widget \fIwidget.\fR.PPOwnership of \fIwidget\fR is transferred to the popup menu or the menubar..PPTheoretically, any widget can be inserted into a popup menu. In practice, this only makes sense with certain widgets..PPIf a widget is not focus enabled ( see QWidget::isFocusEnabled() ), the menu treats it as a separator. This means, the item is not selectable and will never get focus. This way you can for example simply insert a QLabel if you need a popup menu with a title..PPIf the widget is focus enabled, it will get focus when the user traverses the popup menu with the arrow keys. If the widget does not accept ArrowUp and ArrowDown in its key event handler, the focus will move back to the menu when the the respective arrow key is hit one more time. This works for example with a QLineEdit. If the widget accepts the arrow keys itself, it must also provide the possibility to put the focus back on the menu again by calling QWidget::focusNextPrevChild() respectively. Futhermore should the embedded widget close the menu when the user made a selection. This can be done safely by calling.PP.nf.br if ( isVisible() &&.br parentWidget() &&.br parentWidget()->inherits("QPopupMenu") ).br parentWidget()->close();.fi.PPSee also removeItem()..SH "int QMenuData::insertItem ( const QIconSet & icon, QCustomMenuItem * custom, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a custom menu item \fIcustom\fR with an \fIicon.\fR.PPThis only works with popup menus. It is not supported for menu bars. Ownership of \fIcustom\fR is transferred to the popup menu..PPIf you want to connect a custom item to a certain slot, use connectItem()..PPSee also connectItem(), removeItem() and QCustomMenuItem..SH "int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap, QPopupMenu * popup, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with an icon, a pixmap and a sub menu. The icon will be displayed to the left of the pixmap in the item..PPThe \fIpopup\fR must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed or when the menu is deleted..PPReturns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, int accel = 0, int id = -1, int index = -1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with an icon, a pixmap, an accelerator key, an id and an optional index and connects it to an object/slot. The icon will be displayed to the left of the pixmap in the item..PPTo look best when being highlighted as menu item, the pixmap should provide a mask, see QPixmap::mask()..PPReturns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h..SH "int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with an icon and a pixmap. The icon will be displayed to the left of the pixmap in the item. Returns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..PPExamples:.(lqtimage/qtimage.cpp mainlyQt/editor.cpp scrollview/scrollview.cpp layout/layout.cpp progress/progress.cpp menu/menu.cpp grapher/grapher.cpp.)l.SH "int QMenuData::insertItem ( const QIconSet & icon, const QString & text, QPopupMenu * popup, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with an icon, a text and a sub menu. The icon will be displayed to the left of the text in the item..PPThe \fIpopup\fR must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed or when the menu is deleted..PPReturns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertItem ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, int accel = 0, int id = -1, int index = -1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with an icon, a text, an accelerator key, an id and an optional index and connects it to an object/slot. The icon will be displayed to the left of the text in the item..PPSee also removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h..SH "int QMenuData::insertItem ( const QIconSet & icon, const QString & text, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with an icon and a text. The icon will be displayed to the left of the text in the item. Returns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertItem ( const QPixmap & pixmap, QPopupMenu * popup, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with a pixmap and a sub menu. The icon will be displayed to the left of the pixmap in the item..PPThe \fIpopup\fR must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed or when the menu is deleted..PPReturns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertItem ( const QPixmap & pixmap, const QObject * receiver, const char * member, int accel = 0, int id = -1, int index = -1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with a pixmap, an accelerator key, an id and an optional index and connects it to an object/slot..PPTo look best when being highlighted as menu item, the pixmap should provide a mask, see QPixmap::mask()..PPReturns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertItem ( const QPixmap & pixmap, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with a pixmap. Returns the menu item identifier..PPTo look best when being highlighted as menu item, the pixmap should provide a mask, see QPixmap::mask()..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertItem ( const QString & text, QPopupMenu * popup, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with a text and a sub menu..PPThe \fIpopup\fR must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed or when the menu is deleted..PPReturns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertItem ( const QString & text, int id=-1, int index=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPInserts a menu item with a text. Returns the menu item identifier..PPSee also removeItem(), changeItem(), setAccel() and connectItem()..SH "int QMenuData::insertSeparator ( int index=-1 )"Inserts a separator at position \fIindex.\fR The separator becomes the last menu item if \fIindex\fR is negative..PPIn a popup menu, a separator is rendered as a horizontal line. In a Motif menubar, a separator is spacing, so the rest of the items (just "Help", normally) are drawn right-justified. In a Windows menubar, separators are ignored (to comply with the Windows style guide)..PPExamples:.(lscrollview/scrollview.cpp progress/progress.cpp menu/menu.cpp.)l.SH "bool QMenuData::isItemChecked ( int id ) const"Returns TRUE if the menu item has been checked, otherwise FALSE..PPSee also setItemChecked()..PPExamples:.(lprogress/progress.cpp.)l.SH "bool QMenuData::isItemEnabled ( int id ) const"Returns TRUE if the item with identifier \fIid\fR is enabled or FALSE if it is disabled..PPSee also setItemEnabled()..SH "int QMenuData::itemParameter ( int id ) const"Returns the parameter of the activation signal of item \fIid.\fR.PPIf no parameter has been specified for this item with setItemParameter(), the value defaults to \fIid.\fR.PPSee also connectItem(), disconnectItem() and setItemParameter()..SH "void QMenuData::menuContentsChanged () \fC[virtual protected]\fR"Virtual function; notifies subclasses that one or more items have been inserted or removed..PPReimplemented in QMenuBar..SH "void QMenuData::menuDelPopup ( QPopupMenu * ) \fC[virtual protected]\fR"Virtual function; notifies subclasses that a popup menu item has been removed..SH "void QMenuData::menuInsPopup ( QPopupMenu * ) \fC[virtual protected]\fR"Virtual function; notifies subclasses that a popup menu item has been inserted..SH "void QMenuData::menuStateChanged () \fC[virtual protected]\fR"Virtual function; notifies subclasses that one or more items have changed state (enabled/disabled or checked/unchecked)..PPReimplemented in QMenuBar..SH "QPixmap * QMenuData::pixmap ( int id ) const"Returns the pixmap that has been set for menu item \fIid,\fR or 0 if no pixmap has been set..PPSee also changeItem(), text() and iconSet()..SH "void QMenuData::removeItem ( int id )"Removes the menu item which has the identifier \fIid.\fR.PPSee also removeItemAt() and clear()..SH "void QMenuData::removeItemAt ( int index )"Removes the menu item at position \fIindex.\fR.PPSee also removeItem() and clear()..SH "void QMenuData::setAccel ( int key, int id )"Defines an accelerator key for the menu item \fIid.\fR.PPAn accelerator key consists of a key code and a combination of the modifiers \fCSHIFT, CTRL, ALT,\fR or \fCUNICODE_ACCEL\fR (OR'ed or added). The header file qnamespace.h contains a list of key codes..PPDefining an accelerator key generates a text which is added to the menu item, for instance, \fCCTRL\fR + \fCKey_O\fR generates "Ctrl+O". The text is formatted differently for different platforms..PPNote that keyboard accelerators in Qt are not application global, but bound to a certain toplevel window. Accelerators in QPopupMenu items therefore only work for menus that are associated with a certain window. This is true for popup menus that live in a menu bar, for instance. In that case, the accelerator will be installed on the menu bar itself. It also works for stand-alone popup menus that have a toplevel widget in their parentWidget()- chain. The menu will then install its accelerator object on that toplevel widget. For all other cases, use an independent QAccel object..PPExample:.PP.nf.br QMenuBar *mainMenu = new QMenuBar;.br QPopupMenu *fileMenu = new QPopupMenu; // file sub menu.br fileMenu->insertItem( "Open Document", 67 );// add "Open" item.br fileMenu->setAccel( CTRL + Key_O, 67 ); // Control and O to open.br fileMenu->insertItem( "Quit", 69 ); // add "Quit" item.br fileMenu->setAccel( CTRL + ALT + Key_Delete, 69 );.br mainMenu->insertItem( "File", fileMenu ); // add the file menu.fi.PPIf you will need to translate accelerators, use QAccel::stringToKey():.PP.nf.br fileMenu->setAccel( QAccel::stringToKey(tr("Ctrl+O")), 67 );.fi.PPYou can also specify the accelerator in the insertItem() function..PPSee also accel(), insertItem(), QAccel and qnamespace.h..PPExamples:.(lmenu/menu.cpp.)l.SH "void QMenuData::setId ( int index, int id ) \fC[virtual]\fR"Sets the menu identifier of the item at \fIindex\fR to \fIid.\fR.PPIf index is out of range the operation is ignored..PPSee also idAt()..SH "void QMenuData::setItemChecked ( int id, bool check )"Checks the menu item with id \fIid\fR if \fIcheck\fR is TRUE, or unchecks it if \fIcheck\fR is FALSE, and calls QPopupMenu::setCheckable( TRUE ) if necessary..PPSee also isItemChecked()..PPExamples:.(lscrollview/scrollview.cpp progress/progress.cpp.)l.SH "void QMenuData::setItemEnabled ( int id, bool enable )"Enables the menu item with identifier \fIid\fR if \fIenable\fR is TRUE, or disables the item if \fIenable\fR is FALSE..PPSee also isItemEnabled()..PPExamples:.(lprogress/progress.cpp menu/menu.cpp.)l.SH "bool QMenuData::setItemParameter ( int id, int param )"Sets the parameter of the activation signal of item \fIid\fR to \fIparam.\fR.PPIf any receiver takes an integer parameter, this value is passed..PPSee also connectItem(), disconnectItem() and itemParameter()..SH "void QMenuData::setWhatsThis ( int id, const QString & text )"Sets a Whats This help for a certain menu item..PPArguments:.TP\fIid\fR is the menu item id..TP\fItext\fR is the Whats This help text in rich text format ( see QStyleSheet).PPSee also whatsThis()..SH "QString QMenuData::text ( int id ) const"Returns the text that has been set for menu item \fIid,\fR or a null string if no text has been set..PPSee also changeItem(), pixmap() and iconSet()..SH "void QMenuData::updateItem ( int ) \fC[virtual]\fR"Virtual function; notifies subclasses about an item that has been changed..PPReimplemented in QPopupMenu and QMenuBar..SH "QString QMenuData::whatsThis ( int id ) const"Returns the Whats This help text for the specified item \fIid\fR or QString::null if no text has been defined yet..PPSee also setWhatsThis()..SH "SEE ALSO".BR http://doc.trolltech.com/qmenudata.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qmenudata.3qt) and the Qtversion (2.3.8).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -