Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The TQMenuData class is a base class for TQMenuBar and TQPopupMenu. More...
#include <tqmenudata.h>
Inherited by TQMenuBar and TQPopupMenu.
TQMenuData 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).
The menu item sends out an activated() signal when it is chosen and a highlighted() signal when it receives the user input focus.
Menu items are assigned the menu identifier id that is passed in insertItem() or an automatically generated identifier if id 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.
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().
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().)
See also TQAccel, TQPopupMenu, TQAction, and Miscellaneous Classes.
See also setAccel(), TQAccel, and ntqnamespace.h.
If the index is invalid (for example, -1), the object itself is deactivated.
See also text().
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().
Changes the iconset and text of the menu item id to the icon and text respectively.
See also pixmap().
Changes the iconset and pixmap of the menu item id to icon and pixmap respectively.
See also pixmap().
Changes the text of the menu item id. If the item has an icon, the icon remains unchanged.
See also text().
Changes the pixmap of the menu item id. If the item has an icon, the icon remains unchanged.
See also pixmap().
Changes the icon and text of the menu item id.
See also pixmap().
See also removeItem() and removeItemAt().
Examples: mdi/application.cpp and qwerty/qwerty.cpp.
The receiver's slot (or signal) is activated when the menu item is activated.
See also disconnectItem() and setItemParameter().
Example: menu/menu.cpp.
All connections are removed when the menu data object is destroyed.
See also connectItem() and setItemParameter().
Note that TQMenuItem 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.
See also indexOf().
Example: chart/chartform.cpp.
Returns the menu item with identifier id, or 0 if there is no item with this identifier. Changes *parent to point to the parent of the return value.
Note that TQMenuItem 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.
See also indexOf().
See also changeItem(), text(), and pixmap().
See also setId() and indexOf().
See also idAt() and findItem().
Example: scrollview/scrollview.cpp.
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.
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.
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().
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.
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().
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().
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().
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().
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().
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().
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().
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().
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().
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.
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.
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.
See also setItemChecked().
Examples: canvas/canvas.cpp, progress/progress.cpp, and showimg/showimg.cpp.
See also setItemEnabled() and isItemVisible().
See also setItemVisible().
If no parameter has been specified for this item with setItemParameter(), the value defaults to id.
See also connectItem(), disconnectItem(), and setItemParameter().
Reimplemented in TQMenuBar.
Reimplemented in TQMenuBar.
See also changeItem(), text(), and iconSet().
Removes the menu item that has the identifier id.
See also removeItemAt() and clear().
Example: chart/chartform.cpp.
See also removeItem() and clear().
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.
If index is out of range, the operation is ignored.
See also idAt().
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.
See also isItemEnabled().
Examples: mdi/application.cpp, menu/menu.cpp, progress/progress.cpp, and showimg/showimg.cpp.
If any receiver takes an integer parameter, this value is passed.
See also connectItem(), disconnectItem(), and itemParameter().
Example: mdi/application.cpp.
See also isItemVisible() and isItemEnabled().
See also whatsThis().
Examples: application/application.cpp, helpsystem/mainwindow.cpp, and mdi/application.cpp.
See also changeItem(), pixmap(), and iconSet().
Examples: tqdir/tqdir.cpp and showimg/showimg.cpp.
Reimplemented in TQPopupMenu.
See also setWhatsThis().
This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | TQt 3.3.8
|