|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QMenuBar
public class QMenuBar
The QMenuBar class provides a horizontal menu bar. A menu bar consists of a list of pull-down menu items. You add menu items with addMenu()
. For example, asuming that menubar is a pointer to a QMenuBar and fileMenu is a pointer to a QMenu
, the following statement inserts the menu into the menu bar:
menubar.addMenu(fileMenu);The ampersand in the menu item's text sets Alt+F as a shortcut for this menu. (You can use "&&" to get a real ampersand in the menu bar.)
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.Usage
In most main window style applications you would use the menuBar()
function provided in QMainWindow
, adding QMenu
s to the menu bar and adding QAction
s to the pop-up menus.
Example (from the Menus example):
The following code example is written in c++.
fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct);Menu items may be removed with
removeAction()
. Widgets can be added to menus by using instances of the QWidgetAction
class to hold them. These actions can then be inserted into menus in the usual way; see the QMenu
documentation for more details.Platform Dependent Look and Feel
Different platforms have different requirements for the appearance of menu bars and their behavior when the user interacts with them. For example, Windows systems are often configured so that the underlined character mnemonics that indicate keyboard shortcuts for items in the menu bar are only shown when the Alt key is pressed.
![]() Plastique widget style. | The Plastique widget style , like most other styles, handles the Help menu in the same way as it handles any other menu. |
![]() Motif widget style. | The Motif widget style treats Help menus in a special way, placing them at right-hand end of the menu bar. |
Qt::Window
) will be used for the system-wide menu bar. Qt for Mac OS X also provides a menu bar merging feature to make QMenuBar conform more closely to accepted Mac OS X menu bar layout. The merging functionality is based on string matching the title of a QMenu
entry. These strings are translated (using QObject::tr()) in the "QMenuBar" context. If an entry is moved its slots will still fire as if it was in the original place. The table below outlines the strings looked for and where the entry is placed if matched:
about.* | Application Menu | About <application name> | If this entry is not found no About item will appear in the Application Menu |
config, options, setup, settings or preferences | Application Menu | Preferences | If this entry is not found the Settings item will be disabled |
quit or exit | Application Menu | Quit <application name> | If this entry is not found a default Quit item will be created to call QApplication::quit() |
QAction::menuRole()
property. If you want all windows in a Mac application to share one menu bar, you must create a menu bar that does not have a parent. Create a parent-less menu bar this way:
QMenuBar menuBar = new QMenuBar();Note: Do not call
QMainWindow::menuBar()
to create the shared menu bar, because that menu bar will have the QMainWindow
as its parent. That menu bar would only be displayed for the parent QMainWindow
. Note: The text used for the application name in the menu bar is obtained from the value set in the Info.plist file in the application's bundle. See Deploying an Application on Mac OS X for more information. The
QMenuBar on Windows CE
QMenuBar on Windows CE is a wrapper for using the system-wide menu bar, similar to the Mac. This feature is activated for Windows Mobile and integrates QMenuBar with the native soft keys. The left soft key can be controlled with QMenuBar::setDefaultAction() and the right soft key can be used to access the menu bar. hovered()
signal is not supported for the native menu integration. Also, it is not possible to display an icon in a native menu on Windows Mobile.Examples
The Menus example shows how to use QMenuBar and QMenu
. The other main window application examples also provide menus using these classes. QMenu
, QShortcut
, QAction
, GUI Design Handbook: Menu Bar, and Menus Example.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal1 |
hovered
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
triggered
This signal takes 1 generic argument(s). |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QMenuBar()
Constructs a menu bar with parent parent. |
|
QMenuBar(QWidget parent)
Constructs a menu bar with parent parent. |
Method Summary | |
---|---|
QAction |
activeAction()
Returns the QAction that is currently highlighted. |
QAction |
addAction(java.lang.String text)
This is an overloaded member function, provided for convenience. |
QAction |
addAction(java.lang.String text,
java.lang.Object receiver,
java.lang.String method)
This convenience function creates a new action with the given text. |
QAction |
addAction(java.lang.String text,
QSignalEmitter.AbstractSignal signal)
This convenience function creates a new action with the given text. |
QMenu |
addMenu(QIcon icon,
java.lang.String title)
Appends a new QMenu with icon and title to the menu bar. |
QAction |
addMenu(QMenu menu)
Appends menu to the menu bar. |
QMenu |
addMenu(java.lang.String title)
Appends a new QMenu with title to the menu bar. |
QAction |
addSeparator()
Appends a separator to the menu. |
void |
clear()
Removes all the actions from the menu bar. |
protected void |
initStyleOption(QStyleOptionMenuItem option,
QAction action)
Initialize option with the values from the menu bar and information from action. |
QAction |
insertMenu(QAction before,
QMenu menu)
This convenience function inserts menu before action before and returns the menus menuAction(). |
QAction |
insertSeparator(QAction before)
This convenience function creates a new separator action, i. |
boolean |
isDefaultUp()
This property holds the popup orientation. |
void |
setActiveAction(QAction action)
Sets the currently highlighted action to act. |
void |
setDefaultUp(boolean arg__1)
This property holds the popup orientation. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1 hovered
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QAction(named: action)>:
This signal is emitted when a menu action is highlighted; action is the action that caused the event to be sent.
Often this is used to update status information.
triggered()
, and QAction::hovered()
.
public final QSignalEmitter.Signal1 triggered
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QAction(named: action)>:
This signal is emitted when an action in a menu belonging to this menubar is triggered as a result of a mouse click; action is the action that caused the signal to be emitted.
Normally, you connect each menu action to a single slot using QAction::triggered()
, 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.
hovered()
, and QAction::triggered()
.
Constructor Detail |
---|
public QMenuBar()
public QMenuBar(QWidget parent)
Method Detail |
---|
public final QAction activeAction()
QAction
that is currently highlighted. A null pointer will be returned if no action is currently selected. setActiveAction()
.
public final QAction addAction(java.lang.String text)
This convenience function creates a new action with text. The function adds the newly created action to the menu's list of actions, and returns it.
QWidget::addAction()
, and QWidget::actions()
.
public final QAction addMenu(QMenu menu)
Note: The returned QAction
object can be used to hide the corresponding menu.
QWidget::addAction()
, and QMenu::menuAction()
.
public final QMenu addMenu(QIcon icon, java.lang.String title)
QMenu
with icon and title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu. QWidget::addAction()
, and QMenu::menuAction()
.
public final QMenu addMenu(java.lang.String title)
QMenu
with title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu. QWidget::addAction()
, and QMenu::menuAction()
.
public final QAction addSeparator()
public final void clear()
removeAction()
.
public final QAction insertMenu(QAction before, QMenu menu)
QWidget::insertAction()
, and addMenu()
.
public final QAction insertSeparator(QAction before)
QAction::isSeparator()
returning true. The function inserts the newly created action into this menu bar's list of actions before action before and returns it. QWidget::insertAction()
, and addSeparator()
.
public final boolean isDefaultUp()
If the menu would not fit on the screen, the other direction is used automatically.
public final void setActiveAction(QAction action)
activeAction()
.
public final void setDefaultUp(boolean arg__1)
If the menu would not fit on the screen, the other direction is used automatically.
protected final void initStyleOption(QStyleOptionMenuItem option, QAction action)
public final QAction addAction(java.lang.String text, java.lang.Object receiver, java.lang.String method)
public final QAction addAction(java.lang.String text, QSignalEmitter.AbstractSignal signal)
triggered()
signal is connected to the receiver's member slot. The function adds the newly created action to the menu's list of actions and returns it. QWidget::addAction()
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |