QPopupMenu3qt
Popup menu widget
Usage
#include <qpopupmenu.h>
Inherits QFrame and QMenuData.
Public Members
QPopupMenu ( QWidget * parent = 0, const char * name = 0 )
~QPopupMenu ()
void popup ( const QPoint & pos, int indexAtPoint = -1 )
virtual void updateItem ( int id )
virtual void setCheckable ( bool )
bool isCheckable () const
int exec ()
int exec ( const QPoint & pos, int indexAtPoint = 0 )
virtual void setActiveItem ( int i )
int idAt ( int index ) const
int idAt ( const QPoint & pos ) const
int insertTearOffHandle ( int id = -1, int index = -1 )
Signals
void activated ( int id )
void highlighted ( int id )
void aboutToShow ()
void aboutToHide ()
Important Inherited Members
int insertItem ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QString & text, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, int id = -1, int index = -1 )
int insertItem ( const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( QWidget * widget, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, QCustomMenuItem * custom, int id = -1, int index = -1 )
int insertItem ( QCustomMenuItem * custom, int id = -1, int index = -1 )
int insertSeparator ( int index = -1 )
void removeItem ( int id )
void removeItemAt ( int index )
void clear ()
QKeySequence accel ( int id ) const
void setAccel ( const QKeySequence & key, int id )
QIconSet * iconSet ( int id ) const
QString text ( int id ) const
QPixmap * pixmap ( int id ) const
void setWhatsThis ( int id, const QString & text )
QString whatsThis ( int id ) const
void changeItem ( int id, const QString & text )
void changeItem ( int id, const QPixmap & pixmap )
void changeItem ( int id, const QIconSet & icon, const QString & text )
void changeItem ( int id, const QIconSet & icon, const QPixmap & pixmap )
bool isItemEnabled ( int id ) const
void setItemEnabled ( int id, bool enable )
bool isItemChecked ( int id ) const
void setItemChecked ( int id, bool check )
bool isItemVisible ( int id ) const
void setItemVisible ( int id, bool visible )
bool connectItem ( int id, const QObject * receiver, const char * member )
bool disconnectItem ( int id, const QObject * receiver, const char * member )
bool setItemParameter ( int id, int param )
int itemParameter ( int id ) const
Properties
bool checkable - whether the display of check marks on menu items is enabled
Protected Members
int itemHeight ( int row ) const
int itemHeight ( QMenuItem * mi ) const
void drawItem ( QPainter * p, int tab_, QMenuItem * mi, bool act, int x, int y, int w, int h )
virtual void drawContents ( QPainter * p )
int columns () const
Overview
The QPopupMenu class provides a popup menu widget.
A popup menu widget is a selection menu. It can be either a pull-down menu in a menu bar or a standalone context (popup) menu. Pull-down menus are shown by the menu bar when the user clicks on the respective item or presses the specified shortcut key. Use QMenuBar::insertItem() to insert a popup menu into a menu bar. Show a context menu either asynchronously with popup() or synchronously with exec().
Technically, a popup menu consists of a list of menu items. You add items with insertItem(). An item is either a string, a pixmap or a custom item that provides its own drawing function (see QCustomMenuItem). In addition, items can have an optional icon drawn on the very left side and an accelerator key such as" Ctrl+X".
There are three kinds of menu items: separators, menu items that perform an action and menu items that show a submenu. Separators are inserted with insertSeparator(). For submenus, you pass a pointer to a QPopupMenu in your call to insertItem(). All other items are considered action items.
When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is selected. In addition, QPopupMenu provides two signals, activated() and highlighted(), which signal the identifier of the respective menu item. It is sometimes practical to connect several items to one slot. To distinguish between them, specify a slot that takes an integer argument and use setItemParameter() to associate a unique value with each item.
You clear a popup menu with clear() and remove single items with removeItem() or removeItemAt().
A popup menu can display check marks for certain items when enabled with setCheckable(TRUE). You check or uncheck items with setItemChecked().
Items are either enabled or disabled. You toggle their state with setItemEnabled(). Just before a popup menu becomes visible, it emits the aboutToShow() signal. You can use this signal to set the correct enabled/disabled states of all menu items before the user sees it. The corresponding aboutToHide() signal is emitted when the menu hides again.
You can provide What's This? help for single menu items with setWhatsThis(). See QWhatsThis for general information about this kind of lightweight online help.
For ultimate flexibility, you can also add entire widgets as items into a popup menu (for example, a color selector).
A QPopupMenu can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to "tear off" frequently used menus and position them in a convenient place on the screen. If you want that functionality for a certain menu, insert a tear-off handle with insertTearOffHandle(). When using tear-off menus, bear in mind that the concept isn't typically used on Microsoft Windows so users may not be familiar with it. Consider using a QToolBar instead. Tear-off menus cannot contain custom widgets; if the original menu contains a custom widget item, this item is omitted.
menu/menu.cpp is an example of QMenuBar and QPopupMenu use.
[Image Omitted]
[Image Omitted]
See also QMenuBar, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Main Window and Related Classes, and Basic Widgets.
Member function documentation
bool checkable
This property holds whether the display of check marks on menu items is enabled.
When TRUE, the display of check marks on menu items is enabled. Checking is always enabled when in Windows-style.
See also QMenuData::setItemChecked().
Set this property's value with setCheckable() and get this property's value with isCheckable().
Releases
6 releases since Debian 2.2 (Potato); the text changed 4 times.