Qt logo

QMenuData Class Reference


The QMenuData class is a base class for QMenuBar and QPopupMenu. More...

#include <qmenudata.h>

Inherited by QMenuBar and QPopupMenu.

List of all member functions.

Public Members

Protected Members


Detailed Description

The QMenuData class is a base class for QMenuBar and QPopupMenu.

QMenuData has an internal list of menu items. A menu item is a text, pixmap or a separator, and may also have a popup menu (separators have no popup menus).

The menu item sends out an activated() signal when it is selected, and a highlighted() signal when it receives the user input focus.

Menu items can be accessed through identifiers.

See also: QAccel.


Member Function Documentation

QMenuData::QMenuData()

Constructs an empty list.

QMenuData::~QMenuData() [virtual]

Removes all menu items and disconnects any signals that have been connected.

intQMenuData::accel(intid)const

Returns the accelerator key that has been defined for the menu item id, or 0 if it has no accelerator key.

See also: setAccel(), QAccel and qnamespace.h.

voidQMenuData::changeItem(constQIconSet&icon, constQString&text, intid)

This function is obsolete. It is provided to keep old programs working. We strongly advise against using it in new code.

Changes the icon and text of the menu item id.

See also: pixmap().

voidQMenuData::changeItem(constQPixmap&pixmap, intid)

This function is obsolete. It is provided to keep old programs working. We strongly advise against using it in new code.

Changes the pixmap of the menu item id. If the item has an icon, the icon remains unchanged.

See also: pixmap().

voidQMenuData::changeItem(constQString&text, intid)

This function is obsolete. It is provided to keep old programs working. We strongly advise against using it in new code.

Changes the text of the menu item id. If the item has an icon, the icon remains unchanged.

See also: text().

voidQMenuData::changeItem(intid, constQIconSet&icon, constQPixmap&pixmap)

Changes the icon and pixmap of the menu item id.

See also: pixmap().

voidQMenuData::changeItem(intid, constQIconSet&icon, constQString&text)

Changes the icon and text of the menu item id.

See also: pixmap().

voidQMenuData::changeItem(intid, constQPixmap&pixmap)

Changes the pixmap of the menu item id. If the item has an icon, the icon remains unchanged.

See also: pixmap().

voidQMenuData::changeItem(intid, constQString&text)

Changes the text of the menu item id. If the item has an icon, the icon remains unchanged.

See also: text().

voidQMenuData::clear()

Removes all menu items.

See also: removeItem() and removeItemAt().

boolQMenuData::connectItem(intid, constQObject*receiver, constchar*member)

Connects a menu item to a receiver and a slot or signal.

The receiver's slot/signal is activated when the menu item is activated.

uintQMenuData::count()const

Returns the number of items in the menu.

boolQMenuData::disconnectItem(intid, constQObject*receiver, constchar*member)

Disconnects a receiver/member from a menu item.

All connections are removed when the menu data object is destroyed.

QMenuItem*QMenuData::findItem(intid)const

Returns a pointer to the menu item with identifier id, or 0 if there is no item with such an identifier.

See also: indexOf().

QMenuItem*QMenuData::findItem(intid, QMenuData**parent)const

Returns a pointer to the menu item with identifier id, or 0 if there is no item with such an identifier, and changes parent to point to the parent of the return value.

See also: indexOf().

QMenuItem*QMenuData::findPopup(QPopupMenu*popup, int*index=0) [protected]

Internal function that finds the menu item where popup is located, storing its index at index if index is not NULL.

QIconSet*QMenuData::iconSet(intid)const

Returns the icon set that has been set for menu item id, or 0 if no icon set has been set.

See also: changeItem(), text() and pixmap().

intQMenuData::idAt(intindex)const

Returns the identifier of the menu item at position index in the internal list, or -1 if index is out of range.

See also: setId() and indexOf().

intQMenuData::indexOf(intid)const

Returns the index of the menu item with identifier id, or -1 if there is no item with such an identifier.

See also: idAt() and findItem().

Examples: scrollview/scrollview.cpp

intQMenuData::insertItem(constQIconSet&icon, constQPixmap&pixmap, QPopupMenu*popup, intid=-1, intindex=-1)

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. Returns the menu item identifier.

The 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.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

intQMenuData::insertItem(constQIconSet&icon, constQPixmap&pixmap, constQObject*receiver, constchar*member, intaccel=0, intid=-1, intindex=-1)

Inserts a menu item with an icon, a pixmap, an accelerator key, an id and an optional index and connects it to an object/slot. The icon will be displayed to the left of the pixmap in the item.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Note that accelerators only work for QPopupMenu items that live in a menu bar. For stand-alone popup menus, use an independent QAccel object.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h.

intQMenuData::insertItem(constQIconSet&icon, constQPixmap&pixmap, intid=-1, intindex=-1)

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.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

intQMenuData::insertItem(constQIconSet&icon, constQString&text, QPopupMenu*popup, intid=-1, intindex=-1)

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. Returns the menu item identifier.

The 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.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

intQMenuData::insertItem(constQIconSet&icon, constQString&text, constQObject*receiver, constchar*member, intaccel=0, intid=-1, intindex=-1)

Inserts a menu item with an icon, a text, an accelerator key, an id and an optional index and connects it to an object/slot. The icon will be displayed to the left of the text in the item.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Note that accelerators only work for QPopupMenu items that live in a menu bar. For stand-alone popup menus, use an independent QAccel object.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h.

intQMenuData::insertItem(constQIconSet&icon, constQString&text, intid=-1, intindex=-1)

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.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

intQMenuData::insertItem(constQPixmap&pixmap, QPopupMenu*popup, intid=-1, intindex=-1)

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. Returns the menu item identifier.

The 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.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

intQMenuData::insertItem(constQPixmap&pixmap, constQObject*receiver, constchar*member, intaccel=0, intid=-1, intindex=-1)

Inserts a menu item with a pixmap, an accelerator key, an id and an optional index and connects it to an object/slot.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Note that accelerators only work for QPopupMenu items that live in a menu bar. For stand-alone popup menus, use an independent QAccel object.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h.

intQMenuData::insertItem(constQPixmap&pixmap, intid=-1, intindex=-1)

Inserts a menu item with a pixmap. Returns the menu item identifier.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

intQMenuData::insertItem(constQString&text, QPopupMenu*popup, intid=-1, intindex=-1)

Inserts a menu item with a text and a sub menu. Returns the menu item identifier.

The 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.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

Examples: qtimage/qtimage.cpp grapher/grapher.cpp mainlyQt/editor.cpp layout/layout.cpp menu/menu.cpp progress/progress.cpp scrollview/scrollview.cpp

intQMenuData::insertItem(constQString&text, constQObject*receiver, constchar*member, intaccel=0, intid=-1, intindex=-1)

Inserts a menu item with a text, an accelerator key, an id and an optional index and connects it to an object/slot.

Example:

    QMenuBar   *mainMenu = new QMenuBar;
    QPopupMenu *fileMenu = new QPopupMenu;
    fileMenu->insertItem( "New",  myView, SLOT(newFile()), CTRL+Key_N );
    fileMenu->insertItem( "Open", myView, SLOT(open()),    CTRL+Key_O );
    mainMenu->insertItem( "File", fileMenu );

If you will need to translate accelerators, use QAccel::stringToKey() to calculate the accelerator key:

    fileMenu->insertItem( tr("Open"), myView, SLOT(open()),
                          QAccel::stringToKey( tr("Ctrl+O") ) );

In the example above, pressing CTRL+N or selecting "open" from the menu activates the myView->open() function.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Note that accelerators only work for QPopupMenu items that live in a menu bar. For stand-alone popup menus, use an independent QAccel object.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h.

intQMenuData::insertItem(constQString&text, intid=-1, intindex=-1)

Inserts a menu item with a text. Returns the menu item identifier.

The menu item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.

The index specifies the position in the menu. The menu item is appended at the end of the list if index is negative.

Warning: Be careful when passing a literal 0 to insertItem(), as some C++ compilers choose the wrong overloaded function. Cast the 0 to what you mean, eg. (QObject*)0.

See also: removeItem(), changeItem(), setAccel() and connectItem().

voidQMenuData::insertSeparator(intindex=-1)

Inserts a separator at position index. The separator becomes the last menu item if 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, all separator are ignored (to comply with the Windows style guide).

Examples: grapher/grapher.cpp menu/menu.cpp progress/progress.cpp scrollview/scrollview.cpp

boolQMenuData::isItemChecked(intid)const

Returns TRUE if the menu item has been checked, otherwise FALSE.

See also: setItemChecked().

Examples: progress/progress.cpp

boolQMenuData::isItemEnabled(intid)const

Returns TRUE if the item with identifier id is enabled or FALSE if it is disabled.

See also: setItemEnabled().

voidQMenuData::menuContentsChanged() [virtualprotected]

Virtual function; notifies subclasses that one or more items have been inserted or removed.

Reimplemented in QMenuBar.

voidQMenuData::menuDelPopup(QPopupMenu*) [virtualprotected]

Virtual function; notifies subclasses that a popup menu item has been removed.

voidQMenuData::menuInsPopup(QPopupMenu*) [virtualprotected]

Virtual function; notifies subclasses that a popup menu item has been inserted.

voidQMenuData::menuStateChanged() [virtualprotected]

Virtual function; notifies subclasses that one or more items have changed state (enabled/disabled or checked/unchecked).

Reimplemented in QMenuBar.

QPixmap*QMenuData::pixmap(intid)const

Returns the pixmap that has been set for menu item id, or 0 if no pixmap has been set.

See also: changeItem(), text() and iconSet().

voidQMenuData::removeItem(intid)

Removes the menu item which has the identifier id.

See also: removeItemAt() and clear().

voidQMenuData::removeItemAt(intindex)

Removes the menu item at position index.

See also: removeItem() and clear().

voidQMenuData::setAccel(intkey, intid)

Defines an accelerator key for the menu item id.

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 qnamespace.h contains a list of key codes.

Defining an accelerator key generates a text which is added to the menu item, for instance, CTRL + Key_O generates "Ctrl+O". The text is formatted differently for different platforms.

Note that accelerators only work for QPopupMenu items that live in a menu bar. For stand-alone popup menus, use an independent QAccel object.

Example:

    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

If you will need to translate accelerators, use QAccel::stringToKey():

    fileMenu->setAccel( QAccel::stringToKey(tr("Ctrl+O")), 67 );

You can also specify the accelerator in the insertItem() function.

See also: setAccel(), accel(), insertItem(), QAccel and qnamespace.h.

voidQMenuData::setId(intindex, intid) [virtual]

Sets the menu identifier of the item at index to id.

If index is out of range the operation is ignored.

See also: idAt().

voidQMenuData::setItemChecked(intid, boolcheck)

Checks the menu item with id id if check is TRUE, or unchecks it if check is FALSE, and calls setCheckable( TRUE ) if necessary.

See also: isItemChecked().

Examples: grapher/grapher.cpp progress/progress.cpp scrollview/scrollview.cpp

voidQMenuData::setItemEnabled(intid, boolenable)

Enables the menu item with identifier id if enable is TRUE, or disables the item if enable is FALSE.

See also: isItemEnabled().

Examples: menu/menu.cpp progress/progress.cpp

voidQMenuData::setWhatsThis(intid, constQString&text)

Sets a Whats This help for a certain menu item.

Arguments:

See also: whatsThis().

QStringQMenuData::text(intid)const

Returns the text that has been set for menu item id, or a null string if no text has been set.

See also: changeItem(), pixmap() and iconSet().

voidQMenuData::updateItem(int) [virtual]

Virtual function; notifies subclasses about an item that has been changed.

Reimplemented in QMenuBar.

QStringQMenuData::whatsThis(intid)const

Returns the Whats This help text for the specified item id or QString::null if no text has been defined yet.

See also: setWhatsThis().


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright 1999 Troll TechTrademarks
Qt version 2.0.2