You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/man/man3/tqpopupmenu.3qt

811 lines
40 KiB

'\" t
.TH TQPopupMenu 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
TQPopupMenu \- Popup menu widget
.SH SYNOPSIS
\fC#include <tqpopupmenu.h>\fR
.PP
Inherits QFrame and TQMenuData.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQPopupMenu\fR ( TQWidget * parent = 0, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~TQPopupMenu\fR ()"
.br
.ti -1c
.BI "void \fBpopup\fR ( const TQPoint & pos, int indexAtPoint = -1 )"
.br
.ti -1c
.BI "virtual void \fBupdateItem\fR ( int id )"
.br
.ti -1c
.BI "virtual void \fBsetCheckable\fR ( bool )"
.br
.ti -1c
.BI "bool \fBisCheckable\fR () const"
.br
.ti -1c
.BI "int \fBexec\fR ()"
.br
.ti -1c
.BI "int \fBexec\fR ( const TQPoint & pos, int indexAtPoint = 0 )"
.br
.ti -1c
.BI "virtual void \fBsetActiveItem\fR ( int i )"
.br
.ti -1c
.BI "int \fBidAt\fR ( int index ) const"
.br
.ti -1c
.BI "int \fBidAt\fR ( const TQPoint & pos ) const"
.br
.ti -1c
.BI "int \fBinsertTearOffHandle\fR ( int id = -1, int index = -1 )"
.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
.ti -1c
.BI "void \fBaboutToShow\fR ()"
.br
.ti -1c
.BI "void \fBaboutToHide\fR ()"
.br
.in -1c
.SS "Important Inherited Members"
.in +1c
.ti -1c
.BI "int \fBinsertItem\fR ( const TQString & text, const TQObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQIconSet & icon, const TQString & text, const TQObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQPixmap & pixmap, const TQObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQIconSet & icon, const TQPixmap & pixmap, const TQObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQString & text, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQIconSet & icon, const TQString & text, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQString & text, TQPopupMenu * popup, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQIconSet & icon, const TQString & text, TQPopupMenu * popup, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQPixmap & pixmap, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQIconSet & icon, const TQPixmap & pixmap, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQPixmap & pixmap, TQPopupMenu * popup, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQIconSet & icon, const TQPixmap & pixmap, TQPopupMenu * popup, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( TQWidget * widget, int id = -1, int index = -1 )"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQIconSet & 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 \fBremoveItemAt\fR ( int index )"
.br
.ti -1c
.BI "void \fBclear\fR ()"
.br
.ti -1c
.BI "QKeySequence \fBaccel\fR ( int id ) const"
.br
.ti -1c
.BI "void \fBsetAccel\fR ( const QKeySequence & key, int id )"
.br
.ti -1c
.BI "TQIconSet * \fBiconSet\fR ( int id ) const"
.br
.ti -1c
.BI "TQString \fBtext\fR ( int id ) const"
.br
.ti -1c
.BI "TQPixmap * \fBpixmap\fR ( int id ) const"
.br
.ti -1c
.BI "void \fBsetWhatsThis\fR ( int id, const TQString & text )"
.br
.ti -1c
.BI "TQString \fBwhatsThis\fR ( int id ) const"
.br
.ti -1c
.BI "void \fBchangeItem\fR ( int id, const TQString & text )"
.br
.ti -1c
.BI "void \fBchangeItem\fR ( int id, const TQPixmap & pixmap )"
.br
.ti -1c
.BI "void \fBchangeItem\fR ( int id, const TQIconSet & icon, const TQString & text )"
.br
.ti -1c
.BI "void \fBchangeItem\fR ( int id, const TQIconSet & icon, const TQPixmap & pixmap )"
.br
.ti -1c
.BI "bool \fBisItemEnabled\fR ( int id ) const"
.br
.ti -1c
.BI "void \fBsetItemEnabled\fR ( int id, bool enable )"
.br
.ti -1c
.BI "bool \fBisItemChecked\fR ( int id ) const"
.br
.ti -1c
.BI "void \fBsetItemChecked\fR ( int id, bool check )"
.br
.ti -1c
.BI "bool \fBisItemVisible\fR ( int id ) const"
.br
.ti -1c
.BI "void \fBsetItemVisible\fR ( int id, bool visible )"
.br
.ti -1c
.BI "bool \fBconnectItem\fR ( int id, const TQObject * receiver, const char * member )"
.br
.ti -1c
.BI "bool \fBdisconnectItem\fR ( int id, const TQObject * receiver, const char * member )"
.br
.ti -1c
.BI "bool \fBsetItemParameter\fR ( int id, int param )"
.br
.ti -1c
.BI "int \fBitemParameter\fR ( int id ) const"
.br
.in -1c
.SS "Properties"
.in +1c
.ti -1c
.BI "bool \fBcheckable\fR - whether the display of check marks on menu items is enabled"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "int \fBitemHeight\fR ( int row ) const"
.br
.ti -1c
.BI "int \fBitemHeight\fR ( TQMenuItem * mi ) const"
.br
.ti -1c
.BI "void \fBdrawItem\fR ( TQPainter * p, int tab_, TQMenuItem * mi, bool act, int x, int y, int w, int h )"
.br
.ti -1c
.BI "virtual void \fBdrawContents\fR ( TQPainter * p )"
.br
.ti -1c
.BI "int \fBcolumns\fR () const"
.br
.in -1c
.SH DESCRIPTION
The TQPopupMenu class provides a popup menu widget.
.PP
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 TQMenuBar::insertItem() to insert a popup menu into a menu bar. Show a context menu either asynchronously with popup() or synchronously with exec().
.PP
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".
.PP
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 TQPopupMenu in your call to insertItem(). All other items are considered action items.
.PP
When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is selected. In addition, TQPopupMenu 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.
.PP
You clear a popup menu with clear() and remove single items with removeItem() or removeItemAt().
.PP
A popup menu can display check marks for certain items when enabled with setCheckable(TRUE). You check or uncheck items with setItemChecked().
.PP
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.
.PP
You can provide What's This? help for single menu items with setWhatsThis(). See TQWhatsThis for general information about this kind of lightweight online help.
.PP
For ultimate flexibility, you can also add entire widgets as items into a popup menu (for example, a color selector).
.PP
A TQPopupMenu 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 TQToolBar instead. Tear-off menus cannot contain custom widgets; if the original menu contains a custom widget item, this item is omitted.
.PP
menu/menu.cpp is an example of TQMenuBar and TQPopupMenu use.
.PP
.ce 1
.B "[Image Omitted]"
.PP
.ce 1
.B "[Image Omitted]"
.PP
See also TQMenuBar, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Main Window and Related Classes, and Basic Widgets.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQPopupMenu::TQPopupMenu ( TQWidget * parent = 0, const char * name = 0 )"
Constructs a popup menu called \fIname\fR with parent \fIparent\fR.
.PP
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other TQObject).
.SH "TQPopupMenu::~TQPopupMenu ()"
Destroys the popup menu.
.SH "void TQPopupMenu::aboutToHide ()\fC [signal]\fR"
This signal is emitted just before the popup menu is hidden after it has been displayed.
.PP
\fBWarning:\fR Do not open a widget in a slot connected to this signal.
.PP
See also aboutToShow(), setItemEnabled(), setItemChecked(), insertItem(), and removeItem().
.SH "void TQPopupMenu::aboutToShow ()\fC [signal]\fR"
This signal is emitted just before the popup menu is displayed. You can connect it to any slot that sets up the menu contents (e.g. to ensure that the right items are enabled).
.PP
See also aboutToHide(), setItemEnabled(), setItemChecked(), insertItem(), and removeItem().
.PP
Example: mdi/application.cpp.
.SH "QKeySequence TQMenuData::accel ( int id ) const"
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.
.PP
See also setAccel(), QAccel, and ntqnamespace.h.
.SH "void TQPopupMenu::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.
.PP
Normally, you connect each menu item to a single slot using TQMenuData::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.
.PP
See also highlighted() and TQMenuData::insertItem().
.PP
Examples:
.)l grapher/grapher.cpp, helpviewer/helpwindow.cpp, tqdir/tqdir.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, and showimg/showimg.cpp.
.SH "void TQMenuData::changeItem ( int id, const TQString & text )"
Changes the text of the menu item \fIid\fR to \fItext\fR. If the item has an icon, the icon remains unchanged.
.PP
See also text().
.SH "void TQMenuData::changeItem ( int id, const TQPixmap & pixmap )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Changes the pixmap of the menu item \fIid\fR to the pixmap \fIpixmap\fR. If the item has an icon, the icon is unchanged.
.PP
See also pixmap().
.SH "void TQMenuData::changeItem ( int id, const TQIconSet & icon, const TQString & text )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Changes the iconset and text of the menu item \fIid\fR to the \fIicon\fR and \fItext\fR respectively.
.PP
See also pixmap().
.SH "void TQMenuData::changeItem ( int id, const TQIconSet & icon, const TQPixmap & pixmap )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Changes the iconset and pixmap of the menu item \fIid\fR to \fIicon\fR and \fIpixmap\fR respectively.
.PP
See also pixmap().
.SH "void TQMenuData::clear ()"
Removes all menu items.
.PP
See also removeItem() and removeItemAt().
.PP
Examples:
.)l mdi/application.cpp and qwerty/qwerty.cpp.
.SH "int TQPopupMenu::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).
.PP
This functions returns the number of columns necessary.
.PP
See also sizeHint.
.SH "bool TQMenuData::connectItem ( int id, const TQObject * receiver, const char * member )"
Connects the menu item with identifier \fIid\fR to \fIreceiver\fR's \fImember\fR slot or signal.
.PP
The receiver's slot (or signal) is activated when the menu item is activated.
.PP
See also disconnectItem() and setItemParameter().
.PP
Example: menu/menu.cpp.
.SH "bool TQMenuData::disconnectItem ( int id, const TQObject * receiver, const char * member )"
Disconnects the \fIreceiver\fR's \fImember\fR from the menu item with identifier \fIid\fR.
.PP
All connections are removed when the menu data object is destroyed.
.PP
See also connectItem() and setItemParameter().
.SH "void TQPopupMenu::drawContents ( TQPainter * p )\fC [virtual protected]\fR"
Draws all menu items using painter \fIp\fR.
.PP
Reimplemented from QFrame.
.SH "void TQPopupMenu::drawItem ( TQPainter * p, int tab_, TQMenuItem * 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.
.PP
See also TQStyle::drawControl().
.SH "int TQPopupMenu::exec ()"
Executes this popup synchronously.
.PP
This is equivalent to \fCexec(mapToGlobal(TQPoint(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
.fi
or aligned to a widget:
.PP
.nf
.br
exec(somewidget.mapToGlobal(TQPoint(0,0)));
.br
.fi
.PP
Examples:
.)l fileiconview/tqfileiconview.cpp, menu/menu.cpp, and scribble/scribble.cpp.
.SH "int TQPopupMenu::exec ( const TQPoint & pos, int indexAtPoint = 0 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Executes this popup synchronously.
.PP
Opens 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 TQWidget::mapToGlobal().
.PP
The 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).
.PP
Note 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().
.PP
Common usage is to position the popup at the current mouse position:
.PP
.nf
.br
exec( QCursor::pos() );
.br
.fi
or aligned to a widget:
.PP
.nf
.br
exec( somewidget.mapToGlobal(TQPoint(0, 0)) );
.br
.fi
.PP
When 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.
.PP
See also popup() and sizeHint.
.SH "void TQPopupMenu::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.
.PP
See also activated() and TQMenuData::insertItem().
.SH "TQIconSet * TQMenuData::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.
.PP
See also changeItem(), text(), and pixmap().
.SH "int TQPopupMenu::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.
.PP
See also TQMenuData::setId() and TQMenuData::indexOf().
.PP
Example: scrollview/scrollview.cpp.
.SH "int TQPopupMenu::idAt ( const TQPoint & pos ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns the id of the item at \fIpos\fR, or -1 if there is no item there or if it is a separator.
.SH "int TQMenuData::insertItem ( const TQString & text, const TQObject * 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.
.PP
A 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.
.PP
Some 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.
.PP
The number of insert functions may look confusing, but they are actually quite simple to use.
.PP
This 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.
.PP
Example:
.PP
.nf
.br
TQMenuBar *mainMenu = new TQMenuBar;
.br
TQPopupMenu *fileMenu = new TQPopupMenu;
.br
fileMenu->insertItem( "New", myView, TQ_SLOT(newFile()), CTRL+Key_N );
.br
fileMenu->insertItem( "Open", myView, TQ_SLOT(open()), CTRL+Key_O );
.br
mainMenu->insertItem( "File", fileMenu );
.br
.fi
.PP
Not all insert functions take an object/slot parameter or an accelerator key. Use connectItem() and setAccel() on those items.
.PP
If 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, TQ_SLOT(open()),
.br
tr("Ctrl+O") );
.br
.fi
.PP
In the example above, pressing Ctrl+O or selecting "Open" from the menu activates the myView->open() function.
.PP
Some insert functions take a TQIconSet parameter to specify the little menu item icon. Note that you can always pass a TQPixmap object instead.
.PP
The \fIid\fR specifies the identification number associated with the menu item. Note that only positive values are valid, as a negative value will make TQt select a unique id for the item.
.PP
The \fIindex\fR specifies the position in the menu. The menu item is appended at the end of the list if \fIindex\fR is negative.
.PP
Note that keyboard accelerators in TQt are not application-global, instead they are bound to a certain top-level window. For example, accelerators in TQPopupMenu 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(TQObject*)0\fR.
.PP
\fBWarning:\fR On Mac OS X, items that connect to a slot that are inserted into a menubar will not function as we use the native menubar that knows nothing about signals or slots. Instead insert the items into a popup menu and insert the popup menu into the menubar. This may be fixed in a future TQt version.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and ntqnamespace.h.
.PP
Examples:
.)l addressbook/mainwindow.cpp, canvas/canvas.cpp, menu/menu.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, showimg/showimg.cpp, and sound/sound.cpp.
.SH "int TQMenuData::insertItem ( const TQIconSet & icon, const TQString & text, const TQObject * 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.
.PP
Inserts 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.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and ntqnamespace.h.
.SH "int TQMenuData::insertItem ( const TQPixmap & pixmap, const TQObject * 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.
.PP
Inserts 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.
.PP
To look best when being highlighted as a menu item, the pixmap should provide a mask (see TQPixmap::mask()).
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQIconSet & icon, const TQPixmap & pixmap, const TQObject * 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.
.PP
Inserts 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.
.PP
To look best when being highlighted as a menu item, the pixmap should provide a mask (see TQPixmap::mask()).
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and ntqnamespace.h.
.SH "int TQMenuData::insertItem ( const TQString & text, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a menu item with text \fItext\fR, optional id \fIid\fR, and optional \fIindex\fR position.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQIconSet & icon, const TQString & text, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts 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.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQString & text, TQPopupMenu * popup, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a menu item with text \fItext\fR, submenu \fIpopup\fR, optional id \fIid\fR, and optional \fIindex\fR position.
.PP
The \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.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQIconSet & icon, const TQString & text, TQPopupMenu * popup, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts 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.
.PP
The \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.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQPixmap & pixmap, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a menu item with pixmap \fIpixmap\fR, optional id \fIid\fR, and optional \fIindex\fR position.
.PP
To look best when being highlighted as a menu item, the pixmap should provide a mask (see TQPixmap::mask()).
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQIconSet & icon, const TQPixmap & pixmap, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts 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.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQPixmap & pixmap, TQPopupMenu * popup, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a menu item with pixmap \fIpixmap\fR, submenu \fIpopup\fR, optional id \fIid\fR, and optional \fIindex\fR position.
.PP
The \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.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( const TQIconSet & icon, const TQPixmap & pixmap, TQPopupMenu * popup, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a menu item with icon \fIicon\fR, pixmap \fIpixmap\fR submenu \fIpopup\fR, optional id \fIid\fR, and optional \fIindex\fR position. The icon will be displayed to the left of the pixmap in the item.
.PP
The \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.
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
.SH "int TQMenuData::insertItem ( TQWidget * widget, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a menu item that consists of the widget \fIwidget\fR with optional id \fIid\fR, and optional \fIindex\fR position.
.PP
Ownership of \fIwidget\fR is transferred to the popup menu or to the menu bar.
.PP
Theoretically, any widget can be inserted into a popup menu. In practice, this only makes sense with certain widgets.
.PP
If a widget is not focus-enabled (see TQWidget::isFocusEnabled()), the menu treats it as a separator; this means that the item is not selectable and will never get focus. In this way you can, for example, simply insert a TQLabel if you need a popup menu with a title.
.PP
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 \fCArrowUp\fR and \fCArrowDown\fR in its key event handler, the focus will move back to the menu when the respective arrow key is hit one more time. This works with a QLineEdit, for example. If the widget accepts the arrow key itself, it must also provide the possibility to put the focus back on the menu again by calling TQWidget::focusNextPrevChild(). Futhermore, if the embedded widget closes 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("TQPopupMenu") )
.br
parentWidget()->close();
.br
.fi
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem().
.SH "int TQMenuData::insertItem ( const TQIconSet & icon, QCustomMenuItem * custom, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a custom menu item \fIcustom\fR with an \fIicon\fR and with optional id \fIid\fR, and optional \fIindex\fR position.
.PP
This only works with popup menus. It is not supported for menu bars. Ownership of \fIcustom\fR is transferred to the popup menu.
.PP
If you want to connect a custom item to a slot, use connectItem().
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also connectItem(), removeItem(), and QCustomMenuItem.
.SH "int TQMenuData::insertItem ( QCustomMenuItem * custom, int id = -1, int index = -1 )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a custom menu item \fIcustom\fR with optional id \fIid\fR, and optional \fIindex\fR position.
.PP
This only works with popup menus. It is not supported for menu bars. Ownership of \fIcustom\fR is transferred to the popup menu.
.PP
If you want to connect a custom item to a slot, use connectItem().
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also connectItem(), removeItem(), and QCustomMenuItem.
.SH "int TQMenuData::insertSeparator ( int index = -1 )"
Inserts a separator at position \fIindex\fR, and returns the menu identifier number allocated to it. The separator becomes the last menu item if \fIindex\fR is negative.
.PP
In a popup menu a separator is rendered as a horizontal line. In a Motif menu bar a separator is spacing, so the rest of the items (normally just "Help") are drawn right-justified. In a Windows menu bar separators are ignored (to comply with the Windows style guidelines).
.PP
Examples:
.)l addressbook/mainwindow.cpp, menu/menu.cpp, progress/progress.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, showimg/showimg.cpp, and sound/sound.cpp.
.SH "int TQPopupMenu::insertTearOffHandle ( int id = -1, int index = -1 )"
Inserts a tear-off handle into the menu. A tear-off handle is a special menu item that creates a copy of the menu when the menu is selected. This "torn-off" copy lives in a separate window. It contains the same menu items as the original menu, with the exception of the tear-off handle.
.PP
The handle 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.
.PP
The \fIindex\fR specifies the position in the menu. The tear-off handle is appended at the end of the list if \fIindex\fR is negative.
.PP
Example: menu/menu.cpp.
.SH "bool TQPopupMenu::isCheckable () const"
Returns TRUE if the display of check marks on menu items is enabled; otherwise returns FALSE. See the "checkable" property for details.
.SH "bool TQMenuData::isItemChecked ( int id ) const"
Returns TRUE if the menu item with the id \fIid\fR has been checked; otherwise returns FALSE.
.PP
See also setItemChecked().
.PP
Examples:
.)l canvas/canvas.cpp, progress/progress.cpp, and showimg/showimg.cpp.
.SH "bool TQMenuData::isItemEnabled ( int id ) const"
Returns TRUE if the item with identifier \fIid\fR is enabled; otherwise returns FALSE
.PP
See also setItemEnabled() and isItemVisible().
.SH "bool TQMenuData::isItemVisible ( int id ) const"
Returns TRUE if the menu item with the id \fIid\fR is visible; otherwise returns FALSE.
.PP
See also setItemVisible().
.SH "int TQPopupMenu::itemHeight ( int row ) const\fC [protected]\fR"
Calculates the height in pixels of the item in row \fIrow\fR.
.SH "int TQPopupMenu::itemHeight ( TQMenuItem * mi ) const\fC [protected]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Calculates the height in pixels of the menu item \fImi\fR.
.SH "int TQMenuData::itemParameter ( int id ) const"
Returns the parameter of the activation signal of item \fIid\fR.
.PP
If no parameter has been specified for this item with setItemParameter(), the value defaults to \fIid\fR.
.PP
See also connectItem(), disconnectItem(), and setItemParameter().
.SH "TQPixmap * TQMenuData::pixmap ( int id ) const"
Returns the pixmap that has been set for menu item \fIid\fR, or 0 if no pixmap has been set.
.PP
See also changeItem(), text(), and iconSet().
.SH "void TQPopupMenu::popup ( const TQPoint & pos, int indexAtPoint = -1 )"
Displays 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 TQWidget::mapToGlobal().
.PP
When 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.
.PP
Example: listviews/listviews.cpp.
.SH "void TQMenuData::removeItem ( int id )"
Removes the menu item that has the identifier \fIid\fR.
.PP
See also removeItemAt() and clear().
.PP
Example: chart/chartform.cpp.
.SH "void TQMenuData::removeItemAt ( int index )"
Removes the menu item at position \fIindex\fR.
.PP
See also removeItem() and clear().
.SH "void TQMenuData::setAccel ( const QKeySequence & key, int id )"
Sets the accelerator key for the menu item \fIid\fR to \fIkey\fR.
.PP
An accelerator key consists of a key code and a combination of the modifiers SHIFT, CTRL, ALT or UNICODE_ACCEL (OR'ed or added). The header file ntqnamespace.h contains a list of key codes.
.PP
Defining an accelerator key produces a text that is added to the menu item; for instance, CTRL + Key_O produces "Ctrl+O". The text is formatted differently for different platforms.
.PP
Note that keyboard accelerators in TQt are not application-global, instead they are bound to a certain top-level window. For example, accelerators in TQPopupMenu 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
Example:
.PP
.nf
.br
TQMenuBar *mainMenu = new TQMenuBar;
.br
TQPopupMenu *fileMenu = new TQPopupMenu; // file sub menu
.br
fileMenu->insertItem( "Open Document", 67 ); // add "Open" item
.br
fileMenu->setAccel( CTRL + Key_O, 67 ); // Ctrl+O to open
.br
fileMenu->insertItem( "Quit", 69 ); // add "Quit" item
.br
fileMenu->setAccel( CTRL + ALT + Key_Delete, 69 ); // add Alt+Del to quit
.br
mainMenu->insertItem( "File", fileMenu ); // add the file menu
.br
.fi
.PP
If you need to translate accelerators, use tr() with a string:
.PP
.nf
.br
fileMenu->setAccel( tr("Ctrl+O"), 67 );
.br
.fi
.PP
You can also specify the accelerator in the insertItem() function. You may prefer to use TQAction to associate accelerators with menu items.
.PP
See also accel(), insertItem(), QAccel, and TQAction.
.PP
Example: menu/menu.cpp.
.SH "void TQPopupMenu::setActiveItem ( int i )\fC [virtual]\fR"
Sets the currently active item to index \fIi\fR and repaints as necessary.
.SH "void TQPopupMenu::setCheckable ( bool )\fC [virtual]\fR"
Sets whether the display of check marks on menu items is enabled. See the "checkable" property for details.
.SH "void TQMenuData::setItemChecked ( int id, bool check )"
If \fIcheck\fR is TRUE, checks the menu item with id \fIid\fR; otherwise unchecks the menu item with id \fIid\fR. Calls TQPopupMenu::setCheckable( TRUE ) if necessary.
.PP
See also isItemChecked().
.PP
Examples:
.)l canvas/canvas.cpp, grapher/grapher.cpp, mdi/application.cpp, menu/menu.cpp, progress/progress.cpp, scrollview/scrollview.cpp, and showimg/showimg.cpp.
.SH "void TQMenuData::setItemEnabled ( int id, bool enable )"
If \fIenable\fR is TRUE, enables the menu item with identifier \fIid\fR; otherwise disables the menu item with identifier \fIid\fR.
.PP
See also isItemEnabled().
.PP
Examples:
.)l mdi/application.cpp, menu/menu.cpp, progress/progress.cpp, and showimg/showimg.cpp.
.SH "bool TQMenuData::setItemParameter ( int id, int param )"
Sets the parameter of the activation signal of item \fIid\fR to \fIparam\fR.
.PP
If any receiver takes an integer parameter, this value is passed.
.PP
See also connectItem(), disconnectItem(), and itemParameter().
.PP
Example: mdi/application.cpp.
.SH "void TQMenuData::setItemVisible ( int id, bool visible )"
If \fIvisible\fR is TRUE, shows the menu item with id \fIid\fR; otherwise hides the menu item with id \fIid\fR.
.PP
See also isItemVisible() and isItemEnabled().
.SH "void TQMenuData::setWhatsThis ( int id, const TQString & text )"
Sets \fItext\fR as What's This help for the menu item with identifier \fIid\fR.
.PP
See also whatsThis().
.PP
Examples:
.)l application/application.cpp, helpsystem/mainwindow.cpp, and mdi/application.cpp.
.SH "TQString TQMenuData::text ( int id ) const"
Returns the text that has been set for menu item \fIid\fR, or TQString::null if no text has been set.
.PP
See also changeItem(), pixmap(), and iconSet().
.PP
Examples:
.)l tqdir/tqdir.cpp and showimg/showimg.cpp.
.SH "void TQPopupMenu::updateItem ( int id )\fC [virtual]\fR"
Updates the item with identity \fIid\fR.
.PP
Reimplemented from TQMenuData.
.SH "TQString TQMenuData::whatsThis ( int id ) const"
Returns the What's This help text for the item with identifier \fIid\fR or TQString::null if no text has yet been defined.
.PP
See also setWhatsThis().
.SS "Property Documentation"
.SH "bool checkable"
This property holds whether the display of check marks on menu items is enabled.
.PP
When TRUE, the display of check marks on menu items is enabled. Checking is always enabled when in Windows-style.
.PP
See also TQMenuData::setItemChecked().
.PP
Set this property's value with setCheckable() and get this property's value with isCheckable().
.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqpopupmenu.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqpopupmenu.3qt) and the Qt
version (3.3.8).