|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.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.
In most main window style applications you would use the menuBar() provided in QMainWindow, adding QMenus to the menu bar and adding QActions to the popup menus.
Example (from the Menus example):
fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct);
Menu items may be removed with removeAction.
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.
![]() | The Plastique widget style, like most other styles, handles the Help menu in the same way as it handles any other menu. |
![]() | The Motif widget style treats Help menus in a special way, placing them at right-hand end of the menu bar. |
QMenuBar on Qt/Mac is a wrapper for using the system-wide menu bar. If you have multiple menu bars in one dialog the outermost menu bar (normally inside a widget with widget flag Qt::Window) will be used for the system-wide menu bar.
Qt/Mac 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:
String matches | Placement | Notes |
---|---|---|
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() |
You can override this behavior by using the QAction::menuRole() property.
If you wish to make all windows in a Mac application share the same menu bar, you need to create a menu bar that does not have a parent. The menu bar is created like this:
QMenuBar *menuBar = new QMenuBar(0);
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 Qt/Mac for more information.
The Menus example shows how to use QMenuBar and QMenu. The other main window application examples also provide menus using these classes.
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.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary | |
---|---|
QSignalEmitter.Signal1<QAction> |
hovered
This signal is emitted when a menu action is highlighted; action is the action that caused the event to be sent. |
QSignalEmitter.Signal1<QAction> |
triggered
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. |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QMenuBar()
Equivalent to QMenuBar(0). |
|
QMenuBar(QWidget parent)
Constructs a menu bar with parent parent. |
Method Summary | |
---|---|
QAction |
actionAt(QPoint arg__1)
|
protected void |
actionEvent(QActionEvent arg__1)
This function is reimplemented for internal reasons. |
QRect |
actionGeometry(QAction arg__1)
|
QAction |
activeAction()
Returns the QAction that is currently highlighted. |
QAction |
addAction(java.lang.String text)
This convenience function creates a new action with text. |
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. |
protected void |
changeEvent(QEvent arg__1)
This function is reimplemented for internal reasons. |
void |
clear()
Removes all the actions from the menu bar. |
QWidget |
cornerWidget()
Equivalent to cornerWidget(Qt::TopRightCorner). |
QWidget |
cornerWidget(Qt.Corner corner)
|
boolean |
event(QEvent arg__1)
This function is reimplemented for internal reasons. |
boolean |
eventFilter(QObject arg__1,
QEvent arg__2)
This function is reimplemented for internal reasons. |
protected void |
focusInEvent(QFocusEvent arg__1)
This function is reimplemented for internal reasons. |
protected void |
focusOutEvent(QFocusEvent arg__1)
This function is reimplemented for internal reasons. |
static QMenuBar |
fromNativePointer(QNativePointer nativePointer)
This function returns the QMenuBar instance pointed to by nativePointer |
int |
heightForWidth(int arg__1)
This function is reimplemented for internal reasons. |
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.e. an action with QAction::isSeparator() returning true. |
boolean |
isDefaultUp()
Returns the popup orientation. |
protected void |
keyPressEvent(QKeyEvent arg__1)
This function is reimplemented for internal reasons. |
protected void |
leaveEvent(QEvent arg__1)
This function is reimplemented for internal reasons. |
QSize |
minimumSizeHint()
This function is reimplemented for internal reasons. |
protected void |
mouseMoveEvent(QMouseEvent arg__1)
This function is reimplemented for internal reasons. |
protected void |
mousePressEvent(QMouseEvent arg__1)
This function is reimplemented for internal reasons. |
protected void |
mouseReleaseEvent(QMouseEvent arg__1)
This function is reimplemented for internal reasons. |
protected void |
paintEvent(QPaintEvent arg__1)
This function is reimplemented for internal reasons. |
protected void |
resizeEvent(QResizeEvent arg__1)
This function is reimplemented for internal reasons. |
void |
setActiveAction(QAction action)
Sets the currently highlighted action to action. |
void |
setCornerWidget(QWidget w)
Equivalent to setCornerWidget(w, Qt::TopRightCorner). |
void |
setCornerWidget(QWidget w,
Qt.Corner corner)
|
void |
setDefaultUp(boolean arg__1)
Sets the popup orientation to arg__1. |
void |
setVisible(boolean visible)
This function is reimplemented for internal reasons. |
QSize |
sizeHint()
This function is reimplemented for internal reasons. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
disconnect, disconnect, signalSender |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1<QAction> hovered
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.
public final QSignalEmitter.Signal1<QAction> triggered
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.
Constructor Detail |
---|
public QMenuBar()
Equivalent to QMenuBar(0).
public QMenuBar(QWidget parent)
Constructs a menu bar with parent parent.
Method Detail |
---|
public final QAction actionAt(QPoint arg__1)
public final QRect actionGeometry(QAction arg__1)
public final QAction activeAction()
Returns the QAction that is currently highlighted. A null pointer will be returned if no action is currently selected.
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.
public final QAction addMenu(QMenu menu)
Appends menu to the menu bar. Returns the menu's menuAction().
public final QMenu addMenu(QIcon icon, java.lang.String title)
Appends a new QMenu with icon and title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu.
public final QMenu addMenu(java.lang.String title)
Appends a new QMenu with title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu.
public final QAction addSeparator()
Appends a separator to the menu.
public final void clear()
Removes all the actions from the menu bar.
public final QWidget cornerWidget()
Equivalent to cornerWidget(Qt::TopRightCorner).
public final QWidget cornerWidget(Qt.Corner corner)
public final QAction insertMenu(QAction before, QMenu menu)
This convenience function inserts menu before action before and returns the menus menuAction().
public final QAction insertSeparator(QAction before)
This convenience function creates a new separator action, i.e. an action with 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.
public final boolean isDefaultUp()
Returns 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 automatically.
public final void setActiveAction(QAction action)
Sets the currently highlighted action to action.
public final void setCornerWidget(QWidget w)
Equivalent to setCornerWidget(w, Qt::TopRightCorner).
public final void setCornerWidget(QWidget w, Qt.Corner corner)
public final void setDefaultUp(boolean arg__1)
Sets the popup orientation to arg__1.
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 automatically.
protected void actionEvent(QActionEvent arg__1)
This function is reimplemented for internal reasons.
actionEvent
in class QWidget
protected void changeEvent(QEvent arg__1)
This function is reimplemented for internal reasons.
changeEvent
in class QWidget
public boolean event(QEvent arg__1)
This function is reimplemented for internal reasons.
event
in class QWidget
public boolean eventFilter(QObject arg__1, QEvent arg__2)
This function is reimplemented for internal reasons.
eventFilter
in class QObject
protected void focusInEvent(QFocusEvent arg__1)
This function is reimplemented for internal reasons.
focusInEvent
in class QWidget
protected void focusOutEvent(QFocusEvent arg__1)
This function is reimplemented for internal reasons.
focusOutEvent
in class QWidget
public int heightForWidth(int arg__1)
This function is reimplemented for internal reasons.
heightForWidth
in class QWidget
protected void keyPressEvent(QKeyEvent arg__1)
This function is reimplemented for internal reasons.
keyPressEvent
in class QWidget
protected void leaveEvent(QEvent arg__1)
This function is reimplemented for internal reasons.
leaveEvent
in class QWidget
public QSize minimumSizeHint()
This function is reimplemented for internal reasons.
minimumSizeHint
in class QWidget
protected void mouseMoveEvent(QMouseEvent arg__1)
This function is reimplemented for internal reasons.
mouseMoveEvent
in class QWidget
Example
protected void mousePressEvent(QMouseEvent arg__1)
This function is reimplemented for internal reasons.
mousePressEvent
in class QWidget
Example
protected void mouseReleaseEvent(QMouseEvent arg__1)
This function is reimplemented for internal reasons.
mouseReleaseEvent
in class QWidget
Example
protected void paintEvent(QPaintEvent arg__1)
This function is reimplemented for internal reasons.
paintEvent
in class QWidget
protected void resizeEvent(QResizeEvent arg__1)
This function is reimplemented for internal reasons.
resizeEvent
in class QWidget
Example
public void setVisible(boolean visible)
This function is reimplemented for internal reasons.
setVisible
in class QWidget
public QSize sizeHint()
This function is reimplemented for internal reasons.
sizeHint
in class QWidget
public static QMenuBar fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.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)
protected final void initStyleOption(QStyleOptionMenuItem option, QAction action)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |