The QMenuData class is a base class for QMenuBar and QPopupMenu.
.PP
QMenuData has an internal list of menu items. A menu item can have a text(), an accelerator, a pixmap(), an iconSet(), a whatsThis() text and a popup menu (unless it is a separator). Menu items may optionally be checked (except for separators).
.PP
The menu item sends out an activated() signal when it is chosen and a highlighted() signal when it receives the user input focus.
.PP
.PP
Menu items are assigned the menu identifier \fIid\fR that is passed in insertItem() or an automatically generated identifier if \fIid\fR is < 0 (the default). The generated identifiers (negative integers) are guaranteed to be unique within the entire application. The identifier is used to access the menu item in other functions.
.PP
Menu items can be removed with removeItem() and removeItemAt(), or changed with changeItem(). All menu items can be removed with clear(). Accelerators can be changed or set with setAccel(). Checkable items can be checked or unchecked with setItemChecked(). Items can be enabled or disabled using setItemEnabled() and connected and disconnected with connectItem() and disconnectItem() respectively. By default, newly created menu items are visible. They can be hidden (and shown again) with setItemVisible().
.PP
Menu items are stored in a list. Use findItem() to find an item by its list position or by its menu identifier. (See also indexOf() and idAt().)
.PP
See also QAccel, QPopupMenu, QAction, and Miscellaneous Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QMenuData::QMenuData ()"
Constructs an empty menu data list.
.SH "QMenuData::~QMenuData ()\fC [virtual]\fR"
Removes all menu items and disconnects any signals that have been connected.
.SH "QKeySequence QMenuData::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.
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 "QMenuItem * QMenuData::findItem ( int id ) const"
Returns the menu item with identifier \fIid\fR, or 0 if there is no item with this identifier.
.PP
Note that QMenuItem is an internal class, and that you should not need to call this function. Use the higher level functions like text(), pixmap() and changeItem() to get and modify menu item attributes instead.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns the menu item with identifier \fIid\fR, or 0 if there is no item with this identifier. Changes \fI*parent\fR to point to the parent of the return value.
.PP
Note that QMenuItem is an internal class, and that you should not need to call this function. Use the higher level functions like text(), pixmap() and changeItem() to get and modify menu item attributes instead.
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.
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.
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.
Note that keyboard accelerators in TQt 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.
\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.
\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.
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).
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 QPixmap::mask()).
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
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 QPixmap::mask()).
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
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().
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().
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 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.
.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 QPixmap::mask()).
.PP
Returns the allocated menu identifier number (\fIid\fR if \fIid\fR >= 0).
.PP
See also removeItem(), changeItem(), setAccel(), and connectItem().
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 QMenuData::insertItem ( const QPixmap & pixmap, QPopupMenu * 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().
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().
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 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 \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:
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 QMenuData::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 QMenuData::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 "bool QMenuData::isItemActive ( int id ) const"
Returns TRUE if the menu item with the id \fIid\fR is currently active; otherwise returns FALSE.
.SH "bool QMenuData::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 QMenuData::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 QMenuData::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 QMenuData::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().
An accelerator key consists of a key code and a combination of the modifiers \fCSHIFT\fR, \fCCTRL\fR, \fCALT\fR or \fCUNICODE_ACCEL\fR (OR'ed or added). The header file ntqnamespace.h contains a list of key codes.
Defining an accelerator key produces a text that is added to the menu item; for instance, \fCCTRL\fR + \fCKey_O\fR produces "Ctrl+O". The text is formatted differently for different platforms.
Note that keyboard accelerators in TQt 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.
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 QAction to associate accelerators with menu items.
.PP
See also accel(), insertItem(), QAccel, and QAction.
.PP
Example: menu/menu.cpp.
.SH "void QMenuData::setId ( int index, int id )\fC [virtual]\fR"
Sets the menu identifier of the item at \fIindex\fR to \fIid\fR.
.PP
If \fIindex\fR is out of range, the operation is ignored.
.PP
See also idAt().
.SH "void QMenuData::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 QPopupMenu::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 QMenuData::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 QMenuData::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 QMenuData::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.