📄 qmenudata.cpp
字号:
if ( accel ) setAccel( accel, actualID ); return actualID;}/*!\overload Inserts a menu item with a text. Returns the menu item identifier. \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QString &text, int id, int index ){ return insertAny( &text, 0, 0, 0, id, index );}/*!\overload Inserts 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. \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QIconSet& icon, const QString &text, int id, int index ){ return insertAny( &text, 0, 0, &icon, id, index );}/*!\overload Inserts a menu item with a text and a sub menu. The \a popup 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. Returns the menu item identifier. \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QString &text, QPopupMenu *popup, int id, int index ){ return insertAny( &text, 0, popup, 0, id, index );}/*!\overload Inserts 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. The \a popup 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. Returns the menu item identifier. \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QIconSet& icon, const QString &text, QPopupMenu *popup, int id, int index ){ return insertAny( &text, 0, popup, &icon, id, index );}/*!\overload Inserts a menu item with a pixmap. Returns the menu item identifier. To look best when being highlighted as menu item, the pixmap should provide a mask, see QPixmap::mask(). \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QPixmap &pixmap, int id, int index ){ return insertAny( 0, &pixmap, 0, 0, id, index );}/*!\overload Inserts 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. \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QIconSet& icon, const QPixmap &pixmap, int id, int index ){ return insertAny( 0, &pixmap, 0, &icon, id, index );}/*!\overload Inserts a menu item with a pixmap and a sub menu. The icon will be displayed to the left of the pixmap in the item. The \a popup 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. Returns the menu item identifier. \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QPixmap &pixmap, QPopupMenu *popup, int id, int index ){ return insertAny( 0, &pixmap, popup, 0, id, index );}/*!\overload Inserts 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. The \a popup 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. Returns the menu item identifier. \sa removeItem(), changeItem(), setAccel(), connectItem()*/int QMenuData::insertItem( const QIconSet& icon, const QPixmap &pixmap, QPopupMenu *popup, int id, int index ){ return insertAny( 0, &pixmap, popup, &icon, id, index );}/*!\overload Inserts a menu item that consists of the widget \a widget. Ownership of \a widget is transferred to the popup menu or the menubar. Theoretically, any widget can be inserted into a popup menu. In practice, this only makes sense with certain widgets. If 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. If 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 \code if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") ) parentWidget()->close(); \endcode \sa removeItem()*/int QMenuData::insertItem( QWidget* widget, int id, int index ){ return insertAny( 0, 0, 0, 0, id, index, widget );}/*!\overload Inserts a custom menu item \a custom. This only works with popup menus. It is not supported for menu bars. Ownership of \a custom is transferred to the popup menu. If you want to connect a custom item to a certain slot, use connectItem(). \sa connectItem(), removeItem(), QCustomMenuItem*/int QMenuData::insertItem( QCustomMenuItem* custom, int id, int index ){ return insertAny( 0, 0, 0, 0, id, index, 0, custom );}/*!\overload Inserts a custom menu item \a custom with an \a icon. This only works with popup menus. It is not supported for menu bars. Ownership of \a custom is transferred to the popup menu. If you want to connect a custom item to a certain slot, use connectItem(). \sa connectItem(), removeItem(), QCustomMenuItem*/int QMenuData::insertItem( const QIconSet& icon, QCustomMenuItem* custom, int id, int index ){ return insertAny( 0, 0, 0, &icon, id, index, 0, custom );}/*! Inserts a separator at position \a index. The separator becomes the last menu item if \a index is negative. In 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).*/int QMenuData::insertSeparator( int index ){ return insertAny( 0, 0, 0, 0, -1, index );}/*! \fn void QMenuData::removeItem( int id ) Removes the menu item which has the identifier \a id. \sa removeItemAt(), clear()*//*! Removes the menu item at position \a index. \sa removeItem(), clear()*/void QMenuData::removeItemAt( int index ){ if ( index < 0 || index >= (int)mitems->count() ) {#if defined(CHECK_RANGE) qWarning( "QMenuData::removeItem: Index %d out of range", index );#endif return; } QMenuItem *mi = mitems->at( index ); if ( mi->popup_menu ) menuDelPopup( mi->popup_menu ); mitems->remove(); if ( !QApplication::closingDown() ) // avoid trouble menuContentsChanged();}/*! Removes all menu items. \sa removeItem(), removeItemAt()*/void QMenuData::clear(){ register QMenuItem *mi = mitems->first(); while ( mi ) { if ( mi->popup_menu ) menuDelPopup( mi->popup_menu ); mitems->remove(); mi = mitems->current(); } if ( !QApplication::closingDown() ) // avoid trouble menuContentsChanged();}/*! Returns the accelerator key that has been defined for the menu item \a id, or 0 if it has no accelerator key. \sa setAccel(), QAccel, qnamespace.h*/int QMenuData::accel( int id ) const{ QMenuItem *mi = findItem( id ); return mi ? mi->key() : 0;}/*! Defines an accelerator key for the menu item \a id. An accelerator key consists of a key code and a combination of the modifiers \c SHIFT, \c CTRL, \c ALT, or \c UNICODE_ACCEL (OR'ed or added). The header file qnamespace.h contains a list of key codes. Defining an accelerator key generates a text which is added to the menu item, for instance, \c CTRL + \c Key_O generates "Ctrl+O". The text is formatted differently for different platforms. Note 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. Example: \code QMenuBar *mainMenu = new QMenuBar; QPopupMenu *fileMenu = new QPopupMenu; // file sub menu fileMenu->insertItem( "Open Document", 67 );// add "Open" item fileMenu->setAccel( CTRL + Key_O, 67 ); // Control and O to open fileMenu->insertItem( "Quit", 69 ); // add "Quit" item fileMenu->setAccel( CTRL + ALT + Key_Delete, 69 ); mainMenu->insertItem( "File", fileMenu ); // add the file menu \endcode If you will need to translate accelerators, use QAccel::stringToKey(): \code fileMenu->setAccel( QAccel::stringToKey(tr("Ctrl+O")), 67 ); \endcode You can also specify the accelerator in the insertItem() function. \sa accel(), insertItem(), QAccel, qnamespace.h*/void QMenuData::setAccel( int key, int id ){ QMenuData *parent; QMenuItem *mi = findItem( id, &parent ); if ( mi ) { mi->accel_key = key; parent->menuContentsChanged(); }}/*! Returns the icon set that has been set for menu item \a id, or 0 if no icon set has been set. \sa changeItem(), text(), pixmap()*/QIconSet* QMenuData::iconSet( int id ) const{ QMenuItem *mi = findItem( id ); return mi ? mi->iconSet() : 0;}/*! Returns the text that has been set for menu item \a id, or a \link QString::operator!() null string\endlink if no text has been set. \sa changeItem(), pixmap(), iconSet()*/QString QMenuData::text( int id ) const{ QMenuItem *mi = findItem( id ); return mi ? mi->text() : QString::null;}/*! Returns the pixmap that has been set for menu item \a id, or 0 if no pixmap has been set. \sa changeItem(), text(), iconSet()*/QPixmap *QMenuData::pixmap( int id ) const{ QMenuItem *mi = findItem( id ); return mi ? mi->pixmap() : 0;}/*!\obsolete Changes the text of the menu item \a id. If the item has an icon, the icon remains unchanged. \sa text()*/void QMenuData::changeItem( const QString &text, int id ){ changeItem( id, text);}/*!\obsolete Changes the pixmap of the menu item \a id. If the item has an icon, the icon remains unchanged. \sa pixmap()*/void QMenuData::changeItem( const QPixmap &pixmap, int id ){ changeItem( id, pixmap );}/*!\obsolete Changes the icon and text of the menu item \a id. \sa pixmap()*/void QMenuData::changeItem( const QIconSet &icon, const QString &text, int id ){ changeItem( id, icon, text );}/*! Changes the text of the menu item \a id. If the item has an icon, the icon remains unchanged. \sa text()*/void QMenuData::changeItem( int id, const QString &text ){ QMenuData *parent; QMenuItem *mi = findItem( id, &parent ); if ( mi ) { // item found if ( mi->text_data == text ) // same string return; if ( mi->pixmap_data ) { // delete pixmap delete mi->pixmap_data; mi->pixmap_data = 0; } mi->text_data = text; if ( !mi->accel_key && text.find( '\t' ) != -1 ) mi->accel_key = Qt::Key_unknown; parent->menuContentsChanged(); }}/*! Changes the pixmap of the menu item \a id. If the item has an icon, the icon remains unchanged. \sa pixmap()*/void QMenuData::changeItem( int id, const QPixmap &pixmap ){ QMenuData *parent; QMenuItem *mi = findItem( id, &parent ); if ( mi ) { // item found register QPixmap *i = mi->pixmap_data; bool fast_refresh = i != 0 && i->width() == pixmap.width() && i->height() == pixmap.height() && !mi->text(); if ( !mi->text_data.isNull() ) // delete text mi->text_data = QString::null; mi->pixmap_data = new QPixmap( pixmap ); delete i; // old mi->pixmap_data, could be &pixmap if ( fast_refresh ) parent->updateItem( id );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -