📄 qpopupmenu.3qt
字号:
Returns the accelerator key that has been defined for the menu item \fIid\fR, or 0 if it has no accelerator key or if there is no such menu item..PPSee also setAccel(), QAccel, and qnamespace.h..SH "void QPopupMenu::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 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()..PPExamples:.)l helpviewer/helpwindow.cpp, qdir/qdir.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, and showimg/showimg.cpp..SH "void QMenuData::changeItem ( int id, const QString & text )"Changes the text of the menu item \fIid\fR to \fItext\fR. If the item has an icon, the icon remains unchanged..PPSee also text()..SH "void QMenuData::changeItem ( int id, const QPixmap & pixmap )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPChanges the pixmap of the menu item \fIid\fR to the pixmap \fIpixmap\fR. If the item has an icon, the icon is unchanged..PPSee also pixmap()..SH "void QMenuData::changeItem ( int id, const QIconSet & icon, const QString & text )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPChanges the iconset and text of the menu item \fIid\fR to the \fIicon\fR and \fItext\fR respectively..PPSee also pixmap()..SH "void QMenuData::changeItem ( int id, const QIconSet & icon, const QPixmap & pixmap )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPChanges the iconset and pixmap of the menu item \fIid\fR to \fIicon\fR and \fIpixmap\fR respectively..PPSee also pixmap()..SH "void QMenuData::clear ()"Removes all menu items..PPSee also removeItem() and removeItemAt()..PPExamples:.)l mdi/application.cpp and qwerty/qwerty.cpp..SH "int QPopupMenu::columns () const\fC [protected]\fR"If a popup menu does not fit on the screen it lays itself out so that it does fit. It is style dependent what layout means (for example, on Windows it will use multiple columns)..PPThis functions returns the number of columns necessary..PPSee also sizeHint..SH "bool QMenuData::connectItem ( int id, const QObject * receiver, const char * member )"Connects the menu item with identifier \fIid\fR to \fIreceiver\fR's \fImember\fR slot or signal..PPThe receiver's slot (or signal) is activated when the menu item is activated..PPSee also disconnectItem() and setItemParameter()..PPExample: menu/menu.cpp..SH "bool QMenuData::disconnectItem ( int id, const QObject * receiver, const char * member )"Disconnects the \fIreceiver\fR's \fImember\fR from the menu item with identifier \fIid\fR..PPAll connections are removed when the menu data object is destroyed..PPSee also connectItem() and setItemParameter()..SH "void QPopupMenu::drawContents ( QPainter * p )\fC [virtual protected]\fR"Draws all menu items using painter \fIp\fR..PPReimplemented from QFrame..SH "void QPopupMenu::drawItem ( QPainter * p, int tab_, QMenuItem * mi, bool act, int x, int y, int w, int h )\fC [protected]\fR"Draws menu item \fImi\fR in the area \fIx\fR, \fIy\fR, \fIw\fR, \fIh\fR, using painter \fIp\fR. The item is drawn active if \fIact\fR is TRUE or drawn inactive if \fIact\fR is FALSE. The rightmost \fItab_\fR pixels are used for accelerator text..PPSee also QStyle::drawControl()..SH "int QPopupMenu::exec ()"Executes this popup synchronously..PPThis is equivalent to \fCexec(mapToGlobal(QPoint(0,0)))\fR. In most situations you'll want to specify the position yourself, for example at the current mouse position:.PP.nf.br exec(QCursor::pos());.br.fior aligned to a widget:.PP.nf.br exec(somewidget.mapToGlobal(QPoint(0,0)));.br.fi.PPExamples:.)l fileiconview/qfileiconview.cpp, menu/menu.cpp, and scribble/scribble.cpp..SH "int QPopupMenu::exec ( const QPoint & pos, int indexAtPoint = 0 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPExecutes this popup synchronously..PPOpens the popup menu so that the item number \fIindexAtPoint\fR will be at the specified \fIglobal\fR position \fIpos\fR. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal()..PPThe return code is the id of the selected item in either the popup menu or one of its submenus, or -1 if no item is selected (normally because the user pressed Esc)..PPNote that all signals are emitted as usual. If you connect a menu item to a slot and call the menu's exec(), you get the result both via the signal-slot connection and in the return value of exec()..PPCommon usage is to position the popup at the current mouse position:.PP.nf.br exec( QCursor::pos() );.br.fior aligned to a widget:.PP.nf.br exec( somewidget.mapToGlobal(QPoint(0, 0)) );.br.fi.PPWhen positioning a popup with exec() or popup(), bear in mind that you cannot rely on the popup menu's current size(). For performance reasons, the popup adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint(). It calculates the proper size depending on the menu's current contents..PPSee also popup() and sizeHint..SH "void QPopupMenu::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..PPSee also activated() and QMenuData::insertItem()..SH "QIconSet * QMenuData::iconSet ( int id ) const"Returns the icon set that has been set for menu item \fIid\fR, or 0 if no icon set has been set..PPSee also changeItem(), text(), and pixmap()..SH "int QPopupMenu::idAt ( int index ) const"Returns the identifier of the menu item at position \fIindex\fR in the internal list, or -1 if \fIindex\fR is out of range..PPSee also QMenuData::setId() and QMenuData::indexOf()..PPExample: scrollview/scrollview.cpp..SH "int QPopupMenu::idAt ( const QPoint & pos ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the id of the item at \fIpos\fR, or -1 if there is no item there or if it is a separator..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 into existing menus or pulldown menus into 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 );.br fileMenu->insertItem( "Open", myView, SLOT(open()), CTRL+Key_O );.br mainMenu->insertItem( "File", fileMenu );.br.fi.PPNot all insert functions take an object/slot parameter or an accelerator key. Use connectItem() and setAccel() on those items..PPIf you need to translate accelerators, use tr() with the text and accelerator. (For translations use a string key sequence.):.PP.nf.br fileMenu->insertItem( tr("Open"), myView, SLOT(open()),.br tr("Ctrl+O") );.br.fi.PPIn the example above, pressing Ctrl+O 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 \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, instead they are bound to a certain top-level window. For example, accelerators in QPopupMenu items only work for menus that are associated with a certain window. This is true for popup menus that live in a menu bar since their accelerators will then be installed in the menu bar itself. This also applies to stand-alone popup menus that have a top-level widget in their parentWidget() chain. The menu will then install its accelerator object on that top-level widget. For all other cases use an independent QAccel object..PP\fBWarning:\fR Be careful when passing a literal 0 to insertItem() because some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, e.g. \fC(QObject*)0\fR..PPReturns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..PPSee also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and qnamespace.h..PPExamples:.)l addressbook/mainwindow.cpp, canvas/canvas.cpp, mdi/application.cpp, menu/menu.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, and showimg/showimg.cpp..SH "int QMenuData::insertItem ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts a menu item with icon \fIicon\fR, text \fItext\fR, accelerator \fIaccel\fR, optional id \fIid\fR, and optional \fIindex\fR position. The menu item is connected it to the \fIreceiver\fR's \fImember\fR slot. The icon will be displayed to the left of the text in the item..PPReturns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..PPSee also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and qnamespace.h..SH "int QMenuData::insertItem ( const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts a menu item with pixmap \fIpixmap\fR, accelerator \fIaccel\fR, optional id \fIid\fR, and optional \fIindex\fR position. The menu item is connected it to the \fIreceiver\fR's \fImember\fR slot. The icon will be displayed to the left of the text in the item..PPTo look best when being highlighted as a menu item, the pixmap should provide a mask (see QPixmap::mask())..PPReturns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..PPSee also removeItem(), changeItem(), setAccel(), and connectItem()..SH "int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts a menu item with icon \fIicon\fR, pixmap \fIpixmap\fR, accelerator \fIaccel\fR, optional id \fIid\fR, and optional \fIindex\fR position. The icon will be displayed to the left of the pixmap in the item. The item is connected to the \fImember\fR slot in the \fIreceiver\fR object..PPTo look best when being highlighted as a menu item, the pixmap should provide a mask (see QPixmap::mask())..PPReturns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..PPSee also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and qnamespace.h..SH "int QMenuData::insertItem ( const QString & text, int id = -1, int index = -1 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts a menu item with text \fItext\fR, optional id \fIid\fR, and optional \fIindex\fR position..PPReturns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..PPSee also removeItem(), changeItem(), setAccel(), and connectItem()..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 behaves essentially like the above function..PPInserts a menu item with icon \fIicon\fR, text \fItext\fR, optional id \fIid\fR, and optional \fIindex\fR position. The icon will be displayed to the left of the text in the item..PPReturns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..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 behaves essentially like the above function..PPInserts a menu item with text \fItext\fR, submenu \fIpopup\fR, optional id \fIid\fR, and optional \fIindex\fR position..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 allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..PPSee also removeItem(), changeItem(), setAccel(), and connectItem()..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 behaves essentially like the above function..PPInserts a menu item with icon \fIicon\fR, text \fItext\fR, submenu \fIpopup\fR, optional id \fIid\fR, and optional \fIindex\fR position. 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 allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..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 behaves essentially like the above function..PPInserts a menu item with pixmap \fIpixmap\fR, optional id \fIid\fR, and optional \fIindex\fR position..PPTo look best when being highlighted as a menu item, the pixmap should provide a mask (see QPixmap::mask())..PPReturns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0)..PPSee also removeItem(), changeItem(), setAccel(), and connectItem()..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 behaves essentially like the above function..PPInserts a menu item with icon \fIicon\fR, pixmap \fIpixmap\fR, optional id \fIid\fR, and optional \fIindex\fR position. The icon will be displayed to the left of the pixmap in the item.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -