TQPopupMenu Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQPopupMenu Class Reference

The TQPopupMenu class provides a popup menu widget. More...

`#include <ntqpopupmenu.h>`

Inherits TQFrame and TQMenuData.

List of all member functions.

## Public Members

- TQPopupMenu ( TQWidget * parent = 0, const char * name = 0 )
- ~TQPopupMenu ()
- void popup ( const TQPoint & pos, int indexAtPoint = -1 )
- virtual void updateItem ( int id )
- virtual void setCheckable ( bool )
- bool isCheckable () const
- int exec ()
- int exec ( const TQPoint & pos, int indexAtPoint = 0 )
- virtual void setActiveItem ( int i )
- int idAt ( int index ) const
- int idAt ( const TQPoint & 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 TQString & text, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )
- int insertItem ( const TQIconSet & icon, const TQString & text, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )
- int insertItem ( const TQPixmap & pixmap, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )
- int insertItem ( const TQIconSet & icon, const TQPixmap & pixmap, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )
- int insertItem ( const TQString & text, int id = -1, int index = -1 )
- int insertItem ( const TQIconSet & icon, const TQString & text, int id = -1, int index = -1 )
- int insertItem ( const TQString & text, TQPopupMenu * popup, int id = -1, int index = -1 )
- int insertItem ( const TQIconSet & icon, const TQString & text, TQPopupMenu * popup, int id = -1, int index = -1 )
- int insertItem ( const TQPixmap & pixmap, int id = -1, int index = -1 )
- int insertItem ( const TQIconSet & icon, const TQPixmap & pixmap, int id = -1, int index = -1 )
- int insertItem ( const TQPixmap & pixmap, TQPopupMenu * popup, int id = -1, int index = -1 )
- int insertItem ( const TQIconSet & icon, const TQPixmap & pixmap, TQPopupMenu * popup, int id = -1, int index = -1 )
- int insertItem ( TQWidget * widget, int id = -1, int index = -1 )
- int insertItem ( const TQIconSet & icon, TQCustomMenuItem * custom, int id = -1, int index = -1 )
- int insertItem ( TQCustomMenuItem * custom, int id = -1, int index = -1 )
- int insertSeparator ( int index = -1 )
- void removeItem ( int id )
- void removeItemAt ( int index )
- void clear ()
- TQKeySequence accel ( int id ) const
- void setAccel ( const TQKeySequence & key, int id )
- TQIconSet * iconSet ( int id ) const
- TQString text ( int id ) const
- TQPixmap * pixmap ( int id ) const
- void setWhatsThis ( int id, const TQString & text )
- TQString whatsThis ( int id ) const
- void changeItem ( int id, const TQString & text )
- void changeItem ( int id, const TQPixmap & pixmap )
- void changeItem ( int id, const TQIconSet & icon, const TQString & text )
- void changeItem ( int id, const TQIconSet & icon, const TQPixmap & 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 TQObject * receiver, const char * member )
- bool disconnectItem ( int id, const TQObject * 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 ( TQMenuItem * mi ) const
- void drawItem ( TQPainter * p, int tab_, TQMenuItem * mi, bool act, int x, int y, int w, int h )
- virtual void drawContents ( TQPainter * p )
- int columns () const

## Detailed Description

The TQPopupMenu 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 TQMenuBar::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 TQCustomMenuItem). 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 TQPopupMenu 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, 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.

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

menu/menu.cpp is an example of TQMenuBar and TQPopupMenu use.

See also TQMenuBar, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Main Window and Related Classes, and Basic Widgets.

## Member Function Documentation

### TQPopupMenu::TQPopupMenu ( TQWidget * parent = 0, const char * name = 0 )

Constructs a popup menu called name with parent parent.

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

### TQPopupMenu::~TQPopupMenu ()

Destroys the popup menu.

### void TQPopupMenu::aboutToHide ()`[signal]`

This signal is emitted just before the popup menu is hidden after it has been displayed.

Warning: Do not open a widget in a slot connected to this signal.

See also aboutToShow(), setItemEnabled(), setItemChecked(), insertItem(), and removeItem().

### void TQPopupMenu::aboutToShow ()`[signal]`

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

See also aboutToHide(), setItemEnabled(), setItemChecked(), insertItem(), and removeItem().

Example: mdi/application.cpp.

### TQKeySequence TQMenuData::accel ( int id ) const

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

See also setAccel(), TQAccel, and ntqnamespace.h.

### void TQPopupMenu::activated ( int id )`[signal]`

This signal is emitted when a menu item is selected; id is the id of the selected item.

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.

See also highlighted() and TQMenuData::insertItem().

Examples: grapher/grapher.cpp, helpviewer/helpwindow.cpp, qdir/qdir.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, and showimg/showimg.cpp.

### void TQMenuData::changeItem ( int id, const TQString & text )

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

See also text().

### void TQMenuData::changeItem ( int id, const TQPixmap & pixmap )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

See also pixmap().

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

Changes the iconset and text of the menu item id to the icon and text respectively.

See also pixmap().

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

Changes the iconset and pixmap of the menu item id to icon and pixmap respectively.

See also pixmap().

### void TQMenuData::clear ()

Removes all menu items.

See also removeItem() and removeItemAt().

Examples: mdi/application.cpp and qwerty/qwerty.cpp.

### int TQPopupMenu::columns () const`[protected]`

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

This functions returns the number of columns necessary.

See also sizeHint.

### bool TQMenuData::connectItem ( int id, const TQObject * receiver, const char * member )

Connects the menu item with identifier id to receiver's member slot or signal.

The receiver's slot (or signal) is activated when the menu item is activated.

See also disconnectItem() and setItemParameter().

Example: menu/menu.cpp.

### bool TQMenuData::disconnectItem ( int id, const TQObject * receiver, const char * member )

Disconnects the receiver's member from the menu item with identifier id.

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

See also connectItem() and setItemParameter().

### void TQPopupMenu::drawContents ( TQPainter * p )`[virtual protected]`

Draws all menu items using painter p.

Reimplemented from TQFrame.

### void TQPopupMenu::drawItem ( TQPainter * p, int tab_, TQMenuItem * mi, bool act, int x, int y, int w, int h )`[protected]`

Draws menu item mi in the area x, y, w, h, using painter p. The item is drawn active if act is true or drawn inactive if act is false. The rightmost tab_ pixels are used for accelerator text.

See also TQStyle::drawControl().

### int TQPopupMenu::exec ()

Executes this popup synchronously.

This is equivalent to `exec(mapToGlobal(TQPoint(0,0)))`. In most situations you'll want to specify the position yourself, for example at the current mouse position:

            exec(TQCursor::pos());

or aligned to a widget:

            exec(somewidget.mapToGlobal(TQPoint(0,0)));

Examples: fileiconview/qfileiconview.cpp, menu/menu.cpp, and scribble/scribble.cpp.

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

Executes this popup synchronously.

Opens the popup menu so that the item number indexAtPoint will be at the specified global position pos. To translate a widget's local coordinates into global coordinates, use TQWidget::mapToGlobal().

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

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().

Common usage is to position the popup at the current mouse position:

            exec( TQCursor::pos() );

or aligned to a widget:

            exec( somewidget.mapToGlobal(TQPoint(0, 0)) );

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.

See also popup() and sizeHint.

### void TQPopupMenu::highlighted ( int id )`[signal]`

This signal is emitted when a menu item is highlighted; id is the id of the highlighted item.

See also activated() and TQMenuData::insertItem().

### TQIconSet * TQMenuData::iconSet ( int id ) 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().

### int TQPopupMenu::idAt ( int index ) 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 TQMenuData::setId() and TQMenuData::indexOf().

Example: scrollview/scrollview.cpp.

### int TQPopupMenu::idAt ( const TQPoint & pos ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the id of the item at pos, or -1 if there is no item there or if it is a separator.

### int TQMenuData::insertItem ( const TQString & text, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )

The family of insertItem() functions inserts menu items into a popup menu or a menu bar.

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 TQCustomMenuItem) or even widgets into popup menus.

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.

The number of insert functions may look confusing, but they are actually quite simple to use.

This default version inserts a menu item with the text text, the accelerator key accel, an id and an optional index and connects it to the slot member in the object receiver.

Example:

            TQMenuBar   *mainMenu = new TQMenuBar;
            TQPopupMenu *fileMenu = new TQPopupMenu;
            fileMenu->insertItem( "New",  myView, TQ_SLOT(newFile()), CTRL+Key_N );
            fileMenu->insertItem( "Open", myView, TQ_SLOT(open()),    CTRL+Key_O );
            mainMenu->insertItem( "File", fileMenu );

Not all insert functions take an object/slot parameter or an accelerator key. Use connectItem() and setAccel() on those items.

If you need to translate accelerators, use tr() with the text and accelerator. (For translations use a string key sequence.):

            fileMenu->insertItem( tr("Open"), myView, TQ_SLOT(open()),
                                  tr("Ctrl+O") );

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

Some insert functions take a TQIconSet parameter to specify the little menu item icon. Note that you can always pass a TQPixmap object instead.

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

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 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 TQAccel object.

Warning: 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. `(TQObject*)0`.

Warning: 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.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), connectItem(), TQAccel, and ntqnamespace.h.

Examples: addressbook/mainwindow.cpp, canvas/canvas.cpp, menu/menu.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, showimg/showimg.cpp, and sound/sound.cpp.

### int TQMenuData::insertItem ( const TQIconSet & icon, const TQString & text, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with icon icon, text text, accelerator accel, optional id id, and optional index position. The menu item is connected it to the receiver's member slot. The icon will be displayed to the left of the text in the item.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), connectItem(), TQAccel, and ntqnamespace.h.

### int TQMenuData::insertItem ( const TQPixmap & pixmap, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with pixmap pixmap, accelerator accel, optional id id, and optional index position. The menu item is connected it to the receiver's member slot. The icon will be displayed to the left of the text in the item.

To look best when being highlighted as a menu item, the pixmap should provide a mask (see TQPixmap::mask()).

Returns the allocated menu identifier number (id if id >= 0).

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

### int TQMenuData::insertItem ( const TQIconSet & icon, const TQPixmap & pixmap, const TQObject * receiver, const char * member, const TQKeySequence & accel = 0, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with icon icon, pixmap pixmap, accelerator accel, optional id id, and optional index position. The icon will be displayed to the left of the pixmap in the item. The item is connected to the member slot in the receiver object.

To look best when being highlighted as a menu item, the pixmap should provide a mask (see TQPixmap::mask()).

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), connectItem(), TQAccel, and ntqnamespace.h.

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

Inserts a menu item with text text, optional id id, and optional index position.

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item with icon icon, text text, optional id id, and optional index position. The icon will be displayed to the left of the text in the item.

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item with text text, submenu popup, optional id id, and optional index position.

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.

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item with icon icon, text text, submenu popup, optional id id, and optional index position. The icon will be displayed to the left of the text in the item.

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.

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item with pixmap pixmap, optional id id, and optional index position.

To look best when being highlighted as a menu item, the pixmap should provide a mask (see TQPixmap::mask()).

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item with icon icon, pixmap pixmap, optional id id, and optional index position. The icon will be displayed to the left of the pixmap in the item.

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item with pixmap pixmap, submenu popup, optional id id, and optional index position.

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.

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item with icon icon, pixmap pixmap submenu popup, optional id id, and optional index position. The icon will be displayed to the left of the pixmap in the item.

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.

Returns the allocated menu identifier number (id if id >= 0).

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

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

Inserts a menu item that consists of the widget widget with optional id id, and optional index position.

Ownership of widget is transferred to the popup menu or to the menu bar.

Theoretically, any widget can be inserted into a popup menu. In practice, this only makes sense with certain widgets.

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.

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 `ArrowUp` and `ArrowDown` 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 TQLineEdit, 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:

            if ( isVisible() &&
                 parentWidget() &&
                 parentWidget()->inherits("TQPopupMenu") )
                parentWidget()->close();

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem().

### int TQMenuData::insertItem ( const TQIconSet & icon, TQCustomMenuItem * custom, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a custom menu item custom with an icon and with optional id id, and optional index position.

This only works with popup menus. It is not supported for menu bars. Ownership of custom is transferred to the popup menu.

If you want to connect a custom item to a slot, use connectItem().

Returns the allocated menu identifier number (id if id >= 0).

See also connectItem(), removeItem(), and TQCustomMenuItem.

### int TQMenuData::insertItem ( TQCustomMenuItem * custom, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a custom menu item custom with optional id id, and optional index position.

This only works with popup menus. It is not supported for menu bars. Ownership of custom is transferred to the popup menu.

If you want to connect a custom item to a slot, use connectItem().

Returns the allocated menu identifier number (id if id >= 0).

See also connectItem(), removeItem(), and TQCustomMenuItem.

### int TQMenuData::insertSeparator ( int index = -1 )

Inserts a separator at position index, and returns the menu identifier number allocated to it. 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 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).

Examples: addressbook/mainwindow.cpp, menu/menu.cpp, progress/progress.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp, showimg/showimg.cpp, and sound/sound.cpp.

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

The handle 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 tear-off handle is appended at the end of the list if index is negative.

Example: menu/menu.cpp.

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

### bool TQMenuData::isItemChecked ( int id ) const

Returns true if the menu item with the id id has been checked; otherwise returns false.

See also setItemChecked().

Examples: canvas/canvas.cpp, progress/progress.cpp, and showimg/showimg.cpp.

### bool TQMenuData::isItemEnabled ( int id ) const

Returns true if the item with identifier id is enabled; otherwise returns false

See also setItemEnabled() and isItemVisible().

### bool TQMenuData::isItemVisible ( int id ) const

Returns true if the menu item with the id id is visible; otherwise returns false.

See also setItemVisible().

### int TQPopupMenu::itemHeight ( int row ) const`[protected]`

Calculates the height in pixels of the item in row row.

### int TQPopupMenu::itemHeight ( TQMenuItem * mi ) const`[protected]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Calculates the height in pixels of the menu item mi.

### int TQMenuData::itemParameter ( int id ) const

Returns the parameter of the activation signal of item id.

If no parameter has been specified for this item with setItemParameter(), the value defaults to id.

See also connectItem(), disconnectItem(), and setItemParameter().

### TQPixmap * TQMenuData::pixmap ( int id ) 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().

### void TQPopupMenu::popup ( const TQPoint & pos, int indexAtPoint = -1 )

Displays the popup menu so that the item number indexAtPoint will be at the specified global position pos. To translate a widget's local coordinates into global coordinates, use TQWidget::mapToGlobal().

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.

Example: listviews/listviews.cpp.

### void TQMenuData::removeItem ( int id )

Removes the menu item that has the identifier id.

See also removeItemAt() and clear().

Example: chart/chartform.cpp.

### void TQMenuData::removeItemAt ( int index )

Removes the menu item at position index.

See also removeItem() and clear().

### void TQMenuData::setAccel ( const TQKeySequence & key, int id )

Sets the accelerator key for the menu item id to key.

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.

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.

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 TQAccel object.

Example:

            TQMenuBar *mainMenu = new TQMenuBar;
            TQPopupMenu *fileMenu = new TQPopupMenu;       // file sub menu
            fileMenu->insertItem( "Open Document", 67 ); // add "Open" item
            fileMenu->setAccel( CTRL + Key_O, 67 );      // Ctrl+O to open
            fileMenu->insertItem( "Quit", 69 );          // add "Quit" item
            fileMenu->setAccel( CTRL + ALT + Key_Delete, 69 ); // add Alt+Del to quit
            mainMenu->insertItem( "File", fileMenu );    // add the file menu

If you need to translate accelerators, use tr() with a string:

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

You can also specify the accelerator in the insertItem() function. You may prefer to use TQAction to associate accelerators with menu items.

See also accel(), insertItem(), TQAccel, and TQAction.

Example: menu/menu.cpp.

### void TQPopupMenu::setActiveItem ( int i )`[virtual]`

Sets the currently active item to index i and repaints as necessary.

### void TQPopupMenu::setCheckable ( bool )`[virtual]`

Sets whether the display of check marks on menu items is enabled. See the "checkable" property for details.

### void TQMenuData::setItemChecked ( int id, bool check )

If check is true, checks the menu item with id id; otherwise unchecks the menu item with id id. Calls TQPopupMenu::setCheckable( true ) if necessary.

See also isItemChecked().

Examples: canvas/canvas.cpp, grapher/grapher.cpp, mdi/application.cpp, menu/menu.cpp, progress/progress.cpp, scrollview/scrollview.cpp, and showimg/showimg.cpp.

### void TQMenuData::setItemEnabled ( int id, bool enable )

If enable is true, enables the menu item with identifier id; otherwise disables the menu item with identifier id.

See also isItemEnabled().

Examples: mdi/application.cpp, menu/menu.cpp, progress/progress.cpp, and showimg/showimg.cpp.

### bool TQMenuData::setItemParameter ( int id, int param )

Sets the parameter of the activation signal of item id to param.

If any receiver takes an integer parameter, this value is passed.

See also connectItem(), disconnectItem(), and itemParameter().

Example: mdi/application.cpp.

### void TQMenuData::setItemVisible ( int id, bool visible )

If visible is true, shows the menu item with id id; otherwise hides the menu item with id id.

See also isItemVisible() and isItemEnabled().

### void TQMenuData::setWhatsThis ( int id, const TQString & text )

Sets text as What's This help for the menu item with identifier id.

See also whatsThis().

Examples: application/application.cpp, helpsystem/mainwindow.cpp, and mdi/application.cpp.

### TQString TQMenuData::text ( int id ) const

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

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

Examples: qdir/qdir.cpp and showimg/showimg.cpp.

### void TQPopupMenu::updateItem ( int id )`[virtual]`

Updates the item with identity id.

Reimplemented from TQMenuData.

### TQString TQMenuData::whatsThis ( int id ) const

Returns the What's This help text for the item with identifier id or TQString::null if no text has yet been defined.

See also setWhatsThis().

## Property 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 TQMenuData::setItemChecked().

Set this property's value with setCheckable() and get this property's value with isCheckable().

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.