QMenuData Class Reference


The QMenuData class is a base class for QMenuBar and QPopupMenu. (details) (complete member list)

#include <qmenudta.h>

Inherited by QMenuBar and QPopupMenu.

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 string or a pixmap in a menu. 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.


Member Function Documentation

QMenuData::QMenuData ()

Constructs an empty list.

QMenuData::~QMenuData ()

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

long QMenuData::accel (int id) const

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

void QMenuData::changeItem (const char *string, int id)

Changes the string of the menu item id.

void QMenuData::changeItem (const QPixmap &pixmap, int id)

Changes the pixmap of the menu item id.

void QMenuData::clear ()

Removes all menu items.

bool QMenuData::connectItem (int id, const QObject *receiver, const char *member)

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

The receiver will be notified when the menu item is activated.

int QMenuData::count () const

Returns the number of items in the menu.

bool QMenuData::disconnectItem (int id, const QObject *receiver, const char *member)

Disconnects a receiver/member from a menu item.

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

QMenuItem * QMenuData::findItem (int id) const

Returns a pointer to the menu item.

int QMenuData::idAt (int index) const

Returns the identifier of the menu item at position index in the internal list.

int QMenuData::indexOf (int id) const

Returns the index of the menu item.

int QMenuData::insertItem (const char *string, const QObject *receiver, const char *member, long accel=0)

Inserts a menu item with a string and optional accelerator key, and connects it to an object/slot. Returns the menu item identifier.

Example of use:

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

See also: setAccel() and connectItem().

int QMenuData::insertItem (const char *string, int id=-1, int index=-1)

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

The menu item gets the identifier id if id >= 0 or a unique, negative identifier if id == -1 (default). The id must not be less than -1.

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

int QMenuData::insertItem (const char *string, QPopupMenu *popup, int id=-1, int index=-1)

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

The menu item gets the identifier id if id >= 0 or a unique, negative identifier if id == -1 (default). The id must not be less than -1.

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

int QMenuData::insertItem (const QPixmap &pixmap, int id=-1, int index=-1)

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

The menu item gets the identifier id if id >= 0 or a unique, negative identifier if id == -1 (default). The id must not be less than -1.

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

int QMenuData::insertItem (const QPixmap &pixmap, QPopupMenu *popup, int id=-1, int index=-1)

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

The menu item gets the identifier id if id >= 0 or a unique, negative identifier if id == -1 (default). The id must not be less than -1.

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

void QMenuData::insertSeparator (int index)

Inserts a separator at position index. The separator will become the last menu item if index is negative.

bool QMenuData::isItemChecked (int id) const

Returns TRUE if the menu item has been checked.

bool QMenuData::isItemDisabled (int id) const

Returns TRUE if the item is disabled.

void QMenuData::menuContentsChanged ()

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

void QMenuData::menuDelPopup (QPopupMenu *)

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

void QMenuData::menuInsPopup (QPopupMenu *)

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

void QMenuData::menuStateChanged ()

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

QPixmap * QMenuData::pixmap (int id) const

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

void QMenuData::removeItem (int id)

Removes the menu item which has the identifier id.

void QMenuData::removeItemAt (int index)

Removes the menu item at position index.

void QMenuData::setAccel (long key, int id)

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 and ALT (OR'ed or added). The header file qkeycode.h has a list of key codes.

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

Notice that accelerators are only meaningful for popup submenus of a menu bar.

Example of use:

  QPopupMenu *fm = new QPopupMenu;       // file sub menu
  fm->insertItem( "Open Document", 67 ); // add "Open" item
  fm->setAccel( CTRL + Key_O, 67 );
  fm->insertItem( "Quit", 69 );          // add "Quit" item
  fm->setAccel( CTRL + ALT + Key_Delete, 69 );

void QMenuData::setId (int index, int id)

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

If index is out of range the operation is ignored.

void QMenuData::setItemChecked (int id, bool check)

Checks a menu item if check is TRUE, or unchecks it if check is FALSE.

void QMenuData::setItemEnabled (int id, bool enable)

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

const char * QMenuData::string (int id) const

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

void QMenuData::updateItem (int)

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


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

It was generated from the following files:


Generated at 16:17, 1995/06/30 by the webmaster at Troll Tech