![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QMenuBar class provides a horizontal menu bar. More...
#include <qmenubar.h>
Inherits QFrame and QMenuData.
A menu bar consists of a list of submenu items - so-called pull-down menus. You add submenu items with insertItem(). Assuming that menubar is a pointer to a QMenuBar and filemenu is a pointer to a QPopupMenu,
menubar->insertItem( "&File", filemenu );inserts the menu into the menu bar. The ampersand in the item text declares Alt-F as a shortcut for this menu. Use "&&" to get a real ampersand in the menu bar.
Items are either enabled or disabled. You toggle their state with setItemEnabled().
Note that there is no need to lay out a menu bar. It automatically sets its own geometry to the top of the parent widget and changes it appropriately whenever the parent is resized.
menu/menu.cpp is a typical example of QMenuBar and QPopupMenu use.
See also QPopupMenu and GUI Design Handbook: Menu Bar.
This enum type is used to decide whether QMenuBar should draw a separator line at its bottom. The possible values are:
This signal is emitted when a menu item is selected; id is the id of the selected item.
Normally you will connect each menu item to a single slot using QMenuData::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 handy in such cases.
See also highlighted() and QMenuData::insertItem().
Example: progress/progress.cpp.
See also removeItem() and removeItemAt().
Examples: mdi/application.cpp and qwerty/qwerty.cpp.
Reimplemented from QFrame.
Example: showimg/showimg.cpp.
Reimplemented from QWidget.
Example: grapher/grapher.cpp.
Reimplemented from QWidget.
This signal is emitted when a menu item is highlighted; id is the id of the highlighted item.
Normally, you will connect each menu item to a single slot using QMenuData::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 handy in such cases.
See also activated() and QMenuData::insertItem().
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.
Some insertItem() members take a popup menu as an additional argument. Use this to insert submenus to existing menus or pulldown menus to 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:
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 );
Not all insert functions take an object/slot parameter or an accelerator key. Use connectItem() and setAccel() on these items.
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.
Some insert functions take a QIconSet parameter to specify the little menu item icon. Note that you can always pass a QPixmap object instead.
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 keyboard accelerators in Qt are not application-global but are bound to a certain top-level window. Accelerators in QPopupMenu items therefore only work for menus that are associated with a certain window. This is true for popup menus that live in a menu bar, for instance; the accelerator will then be installed on the menu bar itself. It also works for 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.
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., (QObject*)0.
See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h.
Examples: addressbook/mainwindow.cpp, mdi/application.cpp, menu/menu.cpp, progress/progress.cpp, qwerty/qwerty.cpp, scrollview/scrollview.cpp and showimg/showimg.cpp.
Inserts a menu item with an icon, a text, an accelerator key, an id, and an optional index; connects it to an object/slot. The icon will be displayed to the left of the text in the item.
See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h.
Inserts a menu item with a pixmap, an accelerator key, an id and an optional index; connects it to an object/slot.
To look best when being highlighted as menu item, the pixmap should provide a mask (see QPixmap::mask()).
Returns the menu item identifier.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with the icon icon, and the pixmap pixmap The icon will be displayed to the left of the pixmap in the item.
The accelerator key is set to accel and the item is connected it to the member slot in the receiver object.
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.
To look best when being highlighted as menu item, the pixmap should provide a mask (see QPixmap::mask()).
Returns the menu item identifier.
See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel and qnamespace.h.
Inserts a menu item with a text. Returns the menu item identifier.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with the icon icon, and the text text 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.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with a text and a submenu.
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 menu item identifier.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with the icon icon, the text text and the submenu popup. 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.
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 menu item identifier.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with the the pixmap pixmap.
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.
Returns the menu item identifier.
To look best when being highlighted as menu item, the pixmap should provide a mask (see QPixmap::mask()).
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with the icon icon, the pixmap pixmap 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.
Returns the menu item identifier.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with the pixmap pixmap and the submenu popup.
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.
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 menu item identifier.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item with the icon icon, the pixmap pixmap and the submenu popup. 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.
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 menu item identifier.
See also removeItem(), changeItem(), setAccel() and connectItem().
Inserts a menu item that consists of the widget widget.
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 QWidget::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 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 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 QWidget::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("QPopupMenu") ) parentWidget()->close();
See also removeItem().
Inserts a custom menu item custom with an icon.
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 certain slot, use connectItem().
See also connectItem(), removeItem() and QCustomMenuItem.
Inserts a custom menu item custom.
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 certain slot, use connectItem().
See also connectItem(), removeItem() and QCustomMenuItem.
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 guide).
Examples: addressbook/mainwindow.cpp, application/application.cpp, mdi/application.cpp, menu/menu.cpp, progress/progress.cpp, scrollview/scrollview.cpp and showimg/showimg.cpp.
Returns the popup orientation. See the "defaultUp" property for details.
See also setItemEnabled().
You should never need to call this; it is called automatically by QMenuData whenever it needs to be called.
Reimplemented from QMenuData.
You should never need to call this; it is called automatically by QMenuData whenever it needs to be called.
Reimplemented from QMenuData.
See also removeItemAt() and clear().
Returns in which cases a menubar sparator is drawn. See the "separator" property for details.
Sets the popup orientation. See the "defaultUp" property for details.
See also isItemEnabled().
Examples: mdi/application.cpp, menu/menu.cpp, progress/progress.cpp and showimg/showimg.cpp.
Sets in which cases a menubar sparator is drawn to when. See the "separator" property for details.
Example: grapher/grapher.cpp.
Reimplemented from QWidget.
This property holds the popup orientation.
The default popup orientation. By default, menus pop "down" the screen. By setting the property to TRUE, the menu will pop "up". You might call this for menus that are below the document to which they refer.
If the menu would not fit on the screen, the other direction is used rather than the default.
Set this property's value with setDefaultUp() and get this property's value with isDefaultUp().
This property holds in which cases a menubar sparator is drawn.
This property is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Set this property's value with setSeparator() and get this property's value with separator().
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta1-beta1
|