Qt 4.8
Public Slots | Signals | Public Functions | Static Public Functions | Protected Functions | Properties | Friends | List of all members
QMenuBar Class Reference

The QMenuBar class provides a horizontal menu bar. More...

#include <qmenubar.h>

Inheritance diagram for QMenuBar:
QWidget QObject QPaintDevice

Public Slots

virtual void setVisible (bool visible)
 Reimplemented Function More...
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void hovered (QAction *action)
 This signal is emitted when a menu action is highlighted; action is the action that caused the event to be sent. More...
 
void triggered (QAction *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. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

QActionactionAt (const QPoint &) const
 Returns the QAction at pt. More...
 
QRect actionGeometry (QAction *) const
 Returns the geometry of action act as a QRect. More...
 
QActionactiveAction () const
 Returns the QAction that is currently highlighted. More...
 
QActionaddAction (const QString &text)
 This convenience function creates a new action with text. More...
 
QActionaddAction (const QString &text, const QObject *receiver, const char *member)
 This convenience function creates a new action with the given text. More...
 
QActionaddMenu (QMenu *menu)
 Appends menu to the menu bar. More...
 
QMenuaddMenu (const QString &title)
 Appends a new QMenu with title to the menu bar. More...
 
QMenuaddMenu (const QIcon &icon, const QString &title)
 Appends a new QMenu with icon and title to the menu bar. More...
 
QActionaddSeparator ()
 Appends a separator to the menu. More...
 
void clear ()
 Removes all the actions from the menu bar. More...
 
QWidgetcornerWidget (Qt::Corner corner=Qt::TopRightCorner) const
 Returns the widget on the left of the first or on the right of the last menu item, depending on corner. More...
 
QActiondefaultAction () const
 Returns the current default action. More...
 
int heightForWidth (int) const
 Reimplemented Function More...
 
QActioninsertMenu (QAction *before, QMenu *menu)
 This convenience function inserts menu before action before and returns the menus menuAction(). More...
 
QActioninsertSeparator (QAction *before)
 This convenience function creates a new separator action, i.e. More...
 
bool isDefaultUp () const
 
bool isNativeMenuBar () const
 
OSMenuRef macMenu ()
 
QSize minimumSizeHint () const
 Reimplemented Function More...
 
 QMenuBar (QWidget *parent=0)
 Constructs a menu bar with parent parent. More...
 
void setActiveAction (QAction *action)
 Sets the currently highlighted action to act. More...
 
void setCornerWidget (QWidget *w, Qt::Corner corner=Qt::TopRightCorner)
 This sets the given widget to be shown directly on the left of the first menu item, or on the right of the last menu item, depending on corner. More...
 
void setDefaultAction (QAction *)
 Sets the default action to act. More...
 
void setDefaultUp (bool)
 
void setNativeMenuBar (bool nativeMenuBar)
 
QSize sizeHint () const
 Reimplemented Function More...
 
 ~QMenuBar ()
 Destroys the menu bar. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery) const
 This method is only relevant for input widgets. More...
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Static Public Functions

static bool macUpdateMenuBar ()
 
static void wceCommands (uint command)
 This function sends native Windows CE commands to Qt menu bars and all their child menus. More...
 
static void wceRefresh ()
 This function refreshes the native Windows CE menu. More...
 
- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 

Protected Functions

void actionEvent (QActionEvent *)
 Reimplemented Function More...
 
void changeEvent (QEvent *)
 Reimplemented Function More...
 
bool event (QEvent *)
 Reimplemented Function More...
 
bool eventFilter (QObject *, QEvent *)
 Reimplemented Function More...
 
void focusInEvent (QFocusEvent *)
 Reimplemented Function More...
 
void focusOutEvent (QFocusEvent *)
 Reimplemented Function More...
 
void initStyleOption (QStyleOptionMenuItem *option, const QAction *action) const
 Initialize option with the values from the menu bar and information from action. More...
 
void keyPressEvent (QKeyEvent *)
 Reimplemented Function More...
 
void leaveEvent (QEvent *)
 Reimplemented Function More...
 
void mouseMoveEvent (QMouseEvent *)
 Reimplemented Function More...
 
void mousePressEvent (QMouseEvent *)
 Reimplemented Function More...
 
void mouseReleaseEvent (QMouseEvent *)
 Reimplemented Function More...
 
void paintEvent (QPaintEvent *)
 Reimplemented Function More...
 
void resizeEvent (QResizeEvent *)
 Reimplemented Function More...
 
void timerEvent (QTimerEvent *)
 Reimplemented Function More...
 
- Protected Functions inherited from QWidget
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
virtual void contextMenuEvent (QContextMenuEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive widget context menu events. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void dragEnterEvent (QDragEnterEvent *)
 This event handler is called when a drag is in progress and the mouse enters this widget. More...
 
virtual void dragLeaveEvent (QDragLeaveEvent *)
 This event handler is called when a drag is in progress and the mouse leaves this widget. More...
 
virtual void dragMoveEvent (QDragMoveEvent *)
 This event handler is called if a drag is in progress, and when any of the following conditions occur: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. More...
 
virtual void dropEvent (QDropEvent *)
 This event handler is called when the drag is dropped on this widget. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void inputMethodEvent (QInputMethodEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events. More...
 
virtual void keyReleaseEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget. More...
 
virtual void languageChange ()
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void showEvent (QShowEvent *)
 This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void wheelEvent (QWheelEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive wheel events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

bool defaultUp
 the popup orientation More...
 
bool nativeMenuBar
 Whether or not a menubar will be used as a native menubar on platforms that support it. More...
 

Friends

class QApplicationPrivate
 
class QMenu
 
class QMenuPrivate
 
bool qt_mac_activate_action (MenuRef, uint, QAction::ActionEvent, bool)
 
class QWidgetPrivate
 
class QWindowsStyle
 

Additional Inherited Members

- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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 QMainWindow::menuBar() function provided in QMainWindow, adding QMenu to the menu bar and adding QAction to the pop-up menus.

Example (from the Menus example):

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-menubar.png
A menu bar shown in the

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-menubar.png
A menu bar shown in the

Motif widget style.

The Motif widget style treats Help menus in a special way, placing them at right-hand end of the menu bar.

QMenuBar on Mac OS X

QMenuBar on Mac OS X 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 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:

String matches Placement Notes
about.* Application Menu | About <application name>=""> The application name is fetched from the {Info.plist} file (see note below). 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 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(0);

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.

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.

The 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 Examples{main window application examples} also provide menus using these classes.

See also
QMenu, QShortcut, QAction, {http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html}{Introduction to Apple Human Interface Guidelines}, {fowler}{GUI Design Handbook: Menu Bar}, {Menus Example}

Definition at line 62 of file qmenubar.h.

Constructors and Destructors

◆ QMenuBar()

QMenuBar::QMenuBar ( QWidget parent = 0)
explicit

Constructs a menu bar with parent parent.

Definition at line 819 of file qmenubar.cpp.

819  : QWidget(*new QMenuBarPrivate, parent, 0)
820 {
821  Q_D(QMenuBar);
822  d->init();
823 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ ~QMenuBar()

QMenuBar::~QMenuBar ( )

Destroys the menu bar.

Definition at line 841 of file qmenubar.cpp.

842 {
843 #ifdef Q_WS_MAC
844  Q_D(QMenuBar);
845  d->macDestroyMenuBar();
846 #endif
847 #ifdef Q_WS_WINCE
848  Q_D(QMenuBar);
849  if (qt_wince_is_mobile())
850  d->wceDestroyMenuBar();
851 #endif
852 #ifdef Q_WS_S60
853  Q_D(QMenuBar);
854  d->symbianDestroyMenuBar();
855 #endif
856 #ifdef Q_WS_X11
857  Q_D(QMenuBar);
858  delete d->cornerWidgetToolBar;
859 #endif
860 }
double d
Definition: qnumeric_p.h:62
bool qt_wince_is_mobile()
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

Functions

◆ actionAt()

QAction * QMenuBar::actionAt ( const QPoint pt) const

Returns the QAction at pt.

Returns 0 if there is no action at pt or if the location has a separator.

\sa addAction(), addSeparator()

Definition at line 1706 of file qmenubar.cpp.

1707 {
1708  Q_D(const QMenuBar);
1709  return d->actionAt(pt);
1710 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ actionEvent()

void QMenuBar::actionEvent ( QActionEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1329 of file qmenubar.cpp.

1330 {
1331  Q_D(QMenuBar);
1332  d->itemsDirty = true;
1333 #ifdef Q_WS_X11
1334  d->platformMenuBar->actionEvent(e);
1335 #endif
1336 #if defined (Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60)
1337  if (isNativeMenuBar()) {
1338 #ifdef Q_WS_MAC
1340 #elif defined(Q_WS_S60)
1341  QMenuBarPrivate::QSymbianMenuBarPrivate *nativeMenuBar = d->symbian_menubar;
1342 #else
1343  QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar;
1344 #endif
1345  if (!nativeMenuBar)
1346  return;
1347  if(e->type() == QEvent::ActionAdded)
1348  nativeMenuBar->addAction(e->action(), e->before());
1349  else if(e->type() == QEvent::ActionRemoved)
1350  nativeMenuBar->removeAction(e->action());
1351  else if(e->type() == QEvent::ActionChanged)
1352  nativeMenuBar->syncAction(e->action());
1353  }
1354 #endif
1355 
1356  if(e->type() == QEvent::ActionAdded) {
1357  connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
1358  connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered()));
1359  } else if(e->type() == QEvent::ActionRemoved) {
1360  e->action()->disconnect(this);
1361  }
1362  if (isVisible()) {
1363  d->updateGeometries();
1364  update();
1365  }
1366 }
QAction * before() const
If type() is ActionAdded , returns the action that should appear before action(). ...
Definition: qevent.h:640
double d
Definition: qnumeric_p.h:62
void syncAction(QWceMenuAction *)
bool isVisible() const
Definition: qwidget.h:1005
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool isNativeMenuBar() const
Definition: qmenubar.cpp:2095
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QAction * action() const
Returns the action that is changed, added, or removed.
Definition: qevent.h:639
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void addAction(QAction *, QAction *=0)
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
void removeAction(QWceMenuAction *)
bool nativeMenuBar
Whether or not a menubar will be used as a native menubar on platforms that support it...
Definition: qmenubar.h:67
void triggered(QAction *action)
This signal is emitted when an action in a menu belonging to this menubar is triggered as a result of...
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void hovered(QAction *action)
This signal is emitted when a menu action is highlighted; action is the action that caused the event ...

◆ actionGeometry()

QRect QMenuBar::actionGeometry ( QAction act) const

Returns the geometry of action act as a QRect.

See also
actionAt()

Definition at line 1717 of file qmenubar.cpp.

Referenced by QAccessibleMenuBar::rect().

1718 {
1719  Q_D(const QMenuBar);
1720  return d->actionRect(act);
1721 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ activeAction()

QAction * QMenuBar::activeAction ( ) const

Returns the QAction that is currently highlighted.

A null pointer will be returned if no action is currently selected.

Definition at line 988 of file qmenubar.cpp.

Referenced by QAccessibleMenuBar::state().

989 {
990  Q_D(const QMenuBar);
991  return d->currentAction;
992 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ addAction() [1/2]

QAction * QMenuBar::addAction ( const QString text)

This convenience function creates a new action with text.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The function adds the newly created action to the menu's list of actions, and returns it.

See also
QWidget::addAction(), QWidget::actions()

Definition at line 874 of file qmenubar.cpp.

Referenced by addAction(), addMenu(), addSeparator(), and defaultAction().

875 {
876  QAction *ret = new QAction(text, this);
877  addAction(ret);
878  return ret;
879 }
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenubar.cpp:874
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ addAction() [2/2]

QAction * QMenuBar::addAction ( const QString text,
const QObject receiver,
const char *  member 
)

This convenience function creates a new action with the given text.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The action's 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.

See also
QWidget::addAction(), QWidget::actions()

Definition at line 894 of file qmenubar.cpp.

895 {
896  QAction *ret = new QAction(text, this);
897  QObject::connect(ret, SIGNAL(triggered(bool)), receiver, member);
898  addAction(ret);
899  return ret;
900 }
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenubar.cpp:874
void triggered(QAction *action)
This signal is emitted when an action in a menu belonging to this menubar is triggered as a result of...
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ addMenu() [1/3]

QAction * QMenuBar::addMenu ( QMenu menu)

Appends menu to the menu bar.

Returns the menu's menuAction().

Note
The returned QAction object can be used to hide the corresponding menu.
See also
QWidget::addAction() QMenu::menuAction()

Definition at line 937 of file qmenubar.cpp.

Referenced by QScriptEngineDebugger::standardWindow().

938 {
939  QAction *action = menu->menuAction();
940  addAction(action);
941  return action;
942 }
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenubar.cpp:874
QAction * menuAction() const
Returns the action associated with this menu.
Definition: qmenu.cpp:711
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ addMenu() [2/3]

QMenu * QMenuBar::addMenu ( const QString title)

Appends a new QMenu with title to the menu bar.

The menu bar takes ownership of the menu. Returns the new menu.

See also
QWidget::addAction() QMenu::menuAction()

Definition at line 908 of file qmenubar.cpp.

909 {
910  QMenu *menu = new QMenu(title, this);
911  addAction(menu->menuAction());
912  return menu;
913 }
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenubar.cpp:874
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
friend class QMenu
Definition: qmenubar.h:350
QAction * menuAction() const
Returns the action associated with this menu.
Definition: qmenu.cpp:711

◆ addMenu() [3/3]

QMenu * QMenuBar::addMenu ( const QIcon icon,
const QString 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.

See also
QWidget::addAction() QMenu::menuAction()

Definition at line 921 of file qmenubar.cpp.

922 {
923  QMenu *menu = new QMenu(title, this);
924  menu->setIcon(icon);
925  addAction(menu->menuAction());
926  return menu;
927 }
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenubar.cpp:874
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setIcon(const QIcon &icon)
Definition: qmenu.cpp:754
friend class QMenu
Definition: qmenubar.h:350
QAction * menuAction() const
Returns the action associated with this menu.
Definition: qmenu.cpp:711

◆ addSeparator()

QAction * QMenuBar::addSeparator ( )

Appends a separator to the menu.

Definition at line 947 of file qmenubar.cpp.

948 {
949  QAction *ret = new QAction(this);
950  ret->setSeparator(true);
951  addAction(ret);
952  return ret;
953 }
void setSeparator(bool b)
If b is true then this action will be considered a separator.
Definition: qaction.cpp:823
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenubar.cpp:874
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ changeEvent()

void QMenuBar::changeEvent ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1520 of file qmenubar.cpp.

1521 {
1522  Q_D(QMenuBar);
1523  if(e->type() == QEvent::StyleChange) {
1524  d->itemsDirty = true;
1526  if(parentWidget())
1528  d->updateGeometries();
1529  } else if (e->type() == QEvent::ParentChange) {
1530  d->handleReparent();
1531  } else if (e->type() == QEvent::FontChange
1532  || e->type() == QEvent::ApplicationFontChange) {
1533  d->itemsDirty = true;
1534  d->updateGeometries();
1535 #ifdef QT_SOFTKEYS_ENABLED
1536  } else if (e->type() == QEvent::LanguageChange) {
1537  if (d->menuBarAction)
1539 #endif
1540  }
1541 
1543 }
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
static QString standardSoftKeyText(StandardSoftKey standardKey)
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
int width() const
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
const char * styleHint(const QFontDef &request)
void setMouseTracking(bool enable)
Definition: qwidget.h:990
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
int heightForWidth(int) const
Reimplemented Function
Definition: qmenubar.cpp:1853
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ clear()

void QMenuBar::clear ( )

Removes all the actions from the menu bar.

Note
On Mac OS X, menu items that have been merged to the system menu bar are not removed by this function. One way to handle this would be to remove the extra actions yourself. You can set the menu role on the different menus, so that you know ahead of time which menu items get merged and which do not. Then decide what to recreate or remove yourself.
See also
removeAction()

Definition at line 1021 of file qmenubar.cpp.

1022 {
1023  QList<QAction*> acts = actions();
1024  for(int i = 0; i < acts.size(); i++)
1025  removeAction(acts[i]);
1026 }
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ cornerWidget()

QWidget * QMenuBar::cornerWidget ( Qt::Corner  corner = Qt::TopRightCorner) const

Returns the widget on the left of the first or on the right of the last menu item, depending on corner.

Note
Using a corner other than Qt::TopRightCorner or Qt::TopLeftCorner will result in a warning.

Definition at line 2022 of file qmenubar.cpp.

Referenced by QMdi::ControlContainer::removeButtonsFromMenuBar(), QMainWindow::setMenuBar(), and QMdi::ControlContainer::showButtonsInMenuBar().

2023 {
2024  Q_D(const QMenuBar);
2025  QWidget *w = 0;
2026  switch(corner) {
2027  case Qt::TopLeftCorner:
2028  w = d->leftWidget;
2029  break;
2030  case Qt::TopRightCorner:
2031  w = d->rightWidget;
2032  break;
2033  default:
2034  qWarning("QMenuBar::cornerWidget: Only TopLeftCorner and TopRightCorner are supported");
2035  break;
2036  }
2037 
2038  return w;
2039 }
double d
Definition: qnumeric_p.h:62
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ defaultAction()

QAction * QMenuBar::defaultAction ( ) const

Returns the current default action.

Since
4.4
See also
setDefaultAction()

Definition at line 2161 of file qmenubar.cpp.

2162 {
2163  return d_func()->defaultAction;
2164 }

◆ event()

bool QMenuBar::event ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1548 of file qmenubar.cpp.

Referenced by eventFilter().

1549 {
1550  Q_D(QMenuBar);
1551  switch (e->type()) {
1552  case QEvent::KeyPress: {
1553  QKeyEvent *ke = (QKeyEvent*)e;
1554 #if 0
1555  if(!d->keyboardState) { //all keypresses..
1556  d->setCurrentAction(0);
1557  return ;
1558  }
1559 #endif
1560  if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
1561  keyPressEvent(ke);
1562  return true;
1563  }
1564 
1565  } break;
1566 #ifndef QT_NO_SHORTCUT
1567  case QEvent::Shortcut: {
1568  QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
1569  int shortcutId = se->shortcutId();
1570  for(int j = 0; j < d->shortcutIndexMap.size(); ++j) {
1571  if (shortcutId == d->shortcutIndexMap.value(j))
1572  d->_q_internalShortcutActivated(j);
1573  }
1574  } break;
1575 #endif
1576  case QEvent::Show:
1577 #ifdef QT3_SUPPORT
1578  if(QWidget *p = parentWidget()) {
1579  // If itemsDirty == true, updateGeometries sends the MenubarUpdated event.
1580  if (!d->itemsDirty) {
1581  QMenubarUpdatedEvent menubarUpdated(this);
1582  QApplication::sendEvent(p, &menubarUpdated);
1583  }
1584  }
1585 #endif
1586  d->_q_updateLayout();
1587  break;
1588  case QEvent::ShortcutOverride: {
1589  QKeyEvent *kev = static_cast<QKeyEvent*>(e);
1590  //we only filter out escape if there is a current action
1591  if (kev->key() == Qt::Key_Escape && d->currentAction) {
1592  e->accept();
1593  return true;
1594  }
1595  }
1596  break;
1597 
1598 #ifdef QT3_SUPPORT
1599  case QEvent::Hide: {
1600  if(QWidget *p = parentWidget()) {
1601  QMenubarUpdatedEvent menubarUpdated(this);
1602  QApplication::sendEvent(p, &menubarUpdated);
1603  }
1604  } break;
1605 #endif
1606 
1607 #ifndef QT_NO_WHATSTHIS
1609  e->setAccepted(d->whatsThis.size());
1610  if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) {
1611  if (action->whatsThis().size() || action->menu())
1612  e->accept();
1613  }
1614  return true;
1615 #endif
1617  d->_q_updateLayout();
1618  break;
1619  default:
1620  break;
1621  }
1622  return QWidget::event(e);
1623 }
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
Definition: qevent.h:675
#define Q_D(Class)
Definition: qglobal.h:2482
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
int shortcutId()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qevent.h:683
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
return(isPopup||isToolTip)
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void keyPressEvent(QKeyEvent *)
Reimplemented Function
Definition: qmenubar.cpp:1199

◆ eventFilter()

bool QMenuBar::eventFilter ( QObject object,
QEvent event 
)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 1628 of file qmenubar.cpp.

1629 {
1630  Q_D(QMenuBar);
1631 #ifdef Q_WS_X11
1632  if (d->platformMenuBar->menuBarEventFilter(object, event)) {
1633  return true;
1634  }
1635 #endif
1636  if (object == parent() && object) {
1637 #ifdef QT3_SUPPORT
1638  if (d->doAutoResize && event->type() == QEvent::Resize) {
1639  QResizeEvent *e = (QResizeEvent *)event;
1640  int w = e->size().width();
1641  setGeometry(0, y(), w, heightForWidth(w));
1642  return false;
1643  }
1644 #endif
1645  if (event->type() == QEvent::ParentChange) //GrandparentChange
1646  d->handleReparent();
1647  }
1648  if (object == d->leftWidget || object == d->rightWidget) {
1649  switch (event->type()) {
1650  case QEvent::ShowToParent:
1651  case QEvent::HideToParent:
1652  d->_q_updateLayout();
1653  break;
1654  default:
1655  break;
1656  }
1657  }
1658 
1660  if (d->altPressed) {
1661  switch (event->type()) {
1662  case QEvent::KeyPress:
1663  case QEvent::KeyRelease:
1664  {
1665  QKeyEvent *kev = static_cast<QKeyEvent*>(event);
1666  if (kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta) {
1667  if (event->type() == QEvent::KeyPress) // Alt-press does not interest us, we have the shortcut-override event
1668  break;
1669  d->setKeyboardMode(!d->keyboardState);
1670  }
1671  }
1672  // fall through
1675  case QEvent::MouseMove:
1676  case QEvent::FocusIn:
1677  case QEvent::FocusOut:
1679  d->altPressed = false;
1680  qApp->removeEventFilter(this);
1681  break;
1682  default:
1683  break;
1684  }
1685  } else if (isVisible()) {
1686  if (event->type() == QEvent::ShortcutOverride) {
1687  QKeyEvent *kev = static_cast<QKeyEvent*>(event);
1688  if ((kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta)
1689  && kev->modifiers() == Qt::AltModifier) {
1690  d->altPressed = true;
1691  qApp->installEventFilter(this);
1692  }
1693  }
1694  }
1695  }
1696 
1697  return false;
1698 }
double d
Definition: qnumeric_p.h:62
The QKeyEvent class describes a key event.
Definition: qevent.h:224
int y() const
bool isVisible() const
Definition: qwidget.h:1005
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
int width() const
Returns the width.
Definition: qsize.h:126
#define qApp
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
const char * styleHint(const QFontDef &request)
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
int heightForWidth(int) const
Reimplemented Function
Definition: qmenubar.cpp:1853
const QSize & size() const
Returns the new size of the widget.
Definition: qevent.h:355
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool event(QEvent *)
Reimplemented Function
Definition: qmenubar.cpp:1548
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ focusInEvent()

void QMenuBar::focusInEvent ( QFocusEvent )
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1371 of file qmenubar.cpp.

1372 {
1373  Q_D(QMenuBar);
1374  if(d->keyboardState)
1375  d->focusFirstAction();
1376 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ focusOutEvent()

void QMenuBar::focusOutEvent ( QFocusEvent )
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1381 of file qmenubar.cpp.

1382 {
1383  Q_D(QMenuBar);
1384  if(!d->popupState) {
1385  d->setCurrentAction(0);
1386  d->setKeyboardMode(false);
1387  }
1388 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ heightForWidth()

int QMenuBar::heightForWidth ( int  ) const
virtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1853 of file qmenubar.cpp.

Referenced by changeEvent(), and eventFilter().

1854 {
1855  Q_D(const QMenuBar);
1856 #if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) || defined(Q_WS_X11)
1857  const bool as_gui_menubar = !isNativeMenuBar();
1858 #else
1859  const bool as_gui_menubar = true;
1860 #endif
1861 
1862  const_cast<QMenuBarPrivate*>(d)->updateGeometries();
1863  int height = 0;
1864  const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
1865  int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
1866  int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
1867  if(as_gui_menubar) {
1868  for (int i = 0; i < d->actionRects.count(); ++i)
1869  height = qMax(height, d->actionRects.at(i).height());
1870  if (height) //there is at least one non-null item
1871  height += spaceBelowMenuBar;
1872  height += 2*fw;
1873  height += 2*vmargin;
1874  }
1875  int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
1876 #ifdef Q_WS_X11
1877  if(d->platformMenuBar->allowCornerWidgets()) {
1878 #endif
1879  if(d->leftWidget)
1880  height = qMax(d->leftWidget->sizeHint().height() + margin, height);
1881  if(d->rightWidget)
1882  height = qMax(d->rightWidget->sizeHint().height() + margin, height);
1883 #ifdef Q_WS_X11
1884  }
1885 #endif
1886  if(as_gui_menubar) {
1888  opt.init(this);
1889  opt.menuRect = rect();
1890  opt.state = QStyle::State_None;
1893  return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); //not pretty..
1894  }
1895  return height;
1896 }
QRect menuRect
the rectangle for the entire menu
Definition: qstyleoption.h:449
double d
Definition: qnumeric_p.h:62
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void init(const QWidget *w)
Use initFrom(widget) instead.
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
bool isNativeMenuBar() const
Definition: qmenubar.cpp:2095
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QRect rect() const
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
int height() const
Returns the height.
Definition: qsize.h:129
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ hovered

void QMenuBar::hovered ( QAction action)
signal

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.

See also
triggered(), QAction::hovered()

Referenced by actionEvent(), QMenuPrivate::activateCausedStack(), and qt_mac_activate_action().

◆ initStyleOption()

void QMenuBar::initStyleOption ( QStyleOptionMenuItem option,
const QAction action 
) const
protected

Initialize option with the values from the menu bar and information from action.

This method is useful for subclasses when they need a QStyleOptionMenuItem, but don't want to fill in all the information themselves.

See also
QStyleOption::initFrom() QMenu::initStyleOption()

Definition at line 583 of file qmenubar.cpp.

Referenced by paintEvent().

584 {
585  if (!option || !action)
586  return;
587  Q_D(const QMenuBar);
588  option->palette = palette();
589  option->state = QStyle::State_None;
590  if (isEnabled() && action->isEnabled())
591  option->state |= QStyle::State_Enabled;
592  else
594  option->fontMetrics = fontMetrics();
595  if (d->currentAction && d->currentAction == action) {
596  option->state |= QStyle::State_Selected;
597  if (d->popupState && !d->closePopupMode)
598  option->state |= QStyle::State_Sunken;
599  }
600  if (hasFocus() || d->currentAction)
601  option->state |= QStyle::State_HasFocus;
602  option->menuRect = rect();
605  option->text = action->text();
606  option->icon = action->icon();
607 }
QRect menuRect
the rectangle for the entire menu
Definition: qstyleoption.h:449
double d
Definition: qnumeric_p.h:62
bool isEnabled() const
Definition: qaction.cpp:1208
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QIcon icon
the icon for the menu item
Definition: qstyleoption.h:451
QString text
the action&#39;s descriptive text
Definition: qaction.h:76
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
QString text
the text for the menu item
Definition: qstyleoption.h:450
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
const QPalette & palette() const
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
QIcon icon
the action&#39;s icon
Definition: qaction.h:75
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QRect rect() const
bool isEnabled() const
Definition: qwidget.h:948
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446

◆ insertMenu()

QAction * QMenuBar::insertMenu ( QAction before,
QMenu menu 
)

This convenience function inserts menu before action before and returns the menus menuAction().

See also
QWidget::insertAction() addMenu()

Definition at line 977 of file qmenubar.cpp.

978 {
979  QAction *action = menu->menuAction();
980  insertAction(before, action);
981  return action;
982 }
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget&#39;s list of actions, before the action before.
Definition: qwidget.cpp:3342
QAction * menuAction() const
Returns the action associated with this menu.
Definition: qmenu.cpp:711
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ insertSeparator()

QAction * QMenuBar::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.

See also
QWidget::insertAction(), addSeparator()

Definition at line 963 of file qmenubar.cpp.

Referenced by defaultAction().

964 {
965  QAction *action = new QAction(this);
966  action->setSeparator(true);
967  insertAction(before, action);
968  return action;
969 }
void setSeparator(bool b)
If b is true then this action will be considered a separator.
Definition: qaction.cpp:823
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget&#39;s list of actions, before the action before.
Definition: qwidget.cpp:3342
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ isDefaultUp()

bool QMenuBar::isDefaultUp ( ) const

Definition at line 1049 of file qmenubar.cpp.

1050 {
1051  Q_D(const QMenuBar);
1052  return !d->defaultPopDown;
1053 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ isNativeMenuBar()

bool QMenuBar::isNativeMenuBar ( ) const

Definition at line 2095 of file qmenubar.cpp.

Referenced by actionEvent(), heightForWidth(), QMenuBarPrivate::macUpdateMenuBarImmediatly(), minimumSizeHint(), setVisible(), and sizeHint().

2096 {
2097  Q_D(const QMenuBar);
2098 #ifdef Q_WS_X11
2099  return d->platformMenuBar->isNativeMenuBar();
2100 #else
2101  if (d->nativeMenuBar == -1) {
2103  }
2104  return d->nativeMenuBar;
2105 #endif
2106 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.

◆ keyPressEvent()

void QMenuBar::keyPressEvent ( QKeyEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1199 of file qmenubar.cpp.

Referenced by event().

1200 {
1201  Q_D(QMenuBar);
1202  d->updateGeometries();
1203  int key = e->key();
1204  if(isRightToLeft()) { // in reverse mode open/close key for submenues are reversed
1205  if(key == Qt::Key_Left)
1206  key = Qt::Key_Right;
1207  else if(key == Qt::Key_Right)
1208  key = Qt::Key_Left;
1209  }
1210  if(key == Qt::Key_Tab) //means right
1211  key = Qt::Key_Right;
1212  else if(key == Qt::Key_Backtab) //means left
1213  key = Qt::Key_Left;
1214 
1215  bool key_consumed = false;
1216  switch(key) {
1217  case Qt::Key_Up:
1218  case Qt::Key_Down:
1219  case Qt::Key_Enter:
1220  case Qt::Key_Space:
1221  case Qt::Key_Return: {
1222  if(!style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this) || !d->currentAction)
1223  break;
1224  if(d->currentAction->menu()) {
1225  d->popupAction(d->currentAction, true);
1226  } else if(key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Space) {
1227  d->activateAction(d->currentAction, QAction::Trigger);
1228  d->setCurrentAction(d->currentAction, false);
1229  d->setKeyboardMode(false);
1230  }
1231  key_consumed = true;
1232  break; }
1233 
1234  case Qt::Key_Right:
1235  case Qt::Key_Left: {
1236  if(d->currentAction) {
1237  int index = d->actions.indexOf(d->currentAction);
1238  if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) {
1239  d->setCurrentAction(nextAction, d->popupState, true);
1240  key_consumed = true;
1241  }
1242  }
1243  break; }
1244 
1245  case Qt::Key_Escape:
1246  d->setCurrentAction(0);
1247  d->setKeyboardMode(false);
1248  key_consumed = true;
1249  break;
1250 
1251  default:
1252  key_consumed = false;
1253  }
1254 
1255  if(!key_consumed &&
1256  (!e->modifiers() ||
1257  (e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) {
1258  int clashCount = 0;
1259  QAction *first = 0, *currentSelected = 0, *firstAfterCurrent = 0;
1260  {
1261  QChar c = e->text()[0].toUpper();
1262  for(int i = 0; i < d->actions.size(); ++i) {
1263  if (d->actionRects.at(i).isNull())
1264  continue;
1265  QAction *act = d->actions.at(i);
1266  QString s = act->text();
1267  if(!s.isEmpty()) {
1268  int ampersand = s.indexOf(QLatin1Char('&'));
1269  if(ampersand >= 0) {
1270  if(s[ampersand+1].toUpper() == c) {
1271  clashCount++;
1272  if(!first)
1273  first = act;
1274  if(act == d->currentAction)
1275  currentSelected = act;
1276  else if (!firstAfterCurrent && currentSelected)
1277  firstAfterCurrent = act;
1278  }
1279  }
1280  }
1281  }
1282  }
1283  QAction *next_action = 0;
1284  if(clashCount >= 1) {
1285  if(clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent))
1286  next_action = first;
1287  else
1288  next_action = firstAfterCurrent;
1289  }
1290  if(next_action) {
1291  key_consumed = true;
1292  d->setCurrentAction(next_action, true, true);
1293  }
1294  }
1295  if(key_consumed)
1296  e->accept();
1297  else
1298  e->ignore();
1299 }
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
QString text
the action&#39;s descriptive text
Definition: qaction.h:76
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QStyle * style() const
Definition: qwidget.cpp:2742
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * styleHint(const QFontDef &request)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
int key
quint16 index
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
bool isRightToLeft() const
Definition: qwidget.h:428
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ leaveEvent()

void QMenuBar::leaveEvent ( QEvent )
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1318 of file qmenubar.cpp.

1319 {
1320  Q_D(QMenuBar);
1321  if((!hasFocus() && !d->popupState) ||
1322  (d->currentAction && d->currentAction->menu() == 0))
1323  d->setCurrentAction(0);
1324 }
double d
Definition: qnumeric_p.h:62
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ macMenu()

OSMenuRef QMenuBar::macMenu ( )
Warning
This function is not part of the public interface.

This function will return the OSMenuRef used to create the native menu bar bindings. This OSMenuRef is then set as the root menu for the Menu Manager.

Warning
This function is not portable.
See also
QMenu::macMenu()

Definition at line 1903 of file qmenu_mac.mm.

Referenced by QMenuBarPrivate::macUpdateMenuBarImmediatly().

1903 { return d_func()->macMenu(); }

◆ macUpdateMenuBar()

bool QMenuBar::macUpdateMenuBar ( )
static
Warning
This function is not part of the public interface.

This function will update the current menu bar and set it as the active menu bar in the Menu Manager.

Warning
This function is not portable.
See also
QMenu::macMenu(), QMenuBar::macMenu()

Definition at line 2055 of file qmenu_mac.mm.

Referenced by QApplicationPrivate::globalEventProcessor(), make_win_eventUPP(), onApplicationChangedActivation(), onApplicationWindowChangedActivation(), qt_event_request_menubarupdate(), and setNativeMenuBar().

2056 {
2057 #ifdef QT_MAC_USE_COCOA
2059  qt_cocoaPostMessage(getMenuLoader(), @selector(qtUpdateMenubar));
2060  return true;
2061 #else
2063 #endif
2064 }
static bool macUpdateMenuBarImmediatly()
Definition: qmenu_mac.mm:2066

◆ minimumSizeHint()

QSize QMenuBar::minimumSizeHint ( ) const
virtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1726 of file qmenubar.cpp.

1727 {
1728  Q_D(const QMenuBar);
1729 #if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) || defined(Q_WS_X11)
1730  const bool as_gui_menubar = !isNativeMenuBar();
1731 #else
1732  const bool as_gui_menubar = true;
1733 #endif
1734 
1735  ensurePolished();
1736  QSize ret(0, 0);
1737  const_cast<QMenuBarPrivate*>(d)->updateGeometries();
1738  const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this);
1739  const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
1740  int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
1741  int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
1742  if(as_gui_menubar) {
1743  int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
1744  d->calcActionRects(w - (2 * fw), 0);
1745  for (int i = 0; ret.isNull() && i < d->actions.count(); ++i)
1746  ret = d->actionRects.at(i).size();
1747  if (!d->extension->isHidden())
1748  ret += QSize(d->extension->sizeHint().width(), 0);
1749  ret += QSize(2*fw + hmargin, 2*fw + vmargin);
1750  }
1751  int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
1752 #ifdef Q_WS_X11
1753  if (d->platformMenuBar->allowCornerWidgets()) {
1754 #endif
1755  if(d->leftWidget) {
1756  QSize sz = d->leftWidget->minimumSizeHint();
1757  ret.setWidth(ret.width() + sz.width());
1758  if(sz.height() + margin > ret.height())
1759  ret.setHeight(sz.height() + margin);
1760  }
1761  if(d->rightWidget) {
1762  QSize sz = d->rightWidget->minimumSizeHint();
1763  ret.setWidth(ret.width() + sz.width());
1764  if(sz.height() + margin > ret.height())
1765  ret.setHeight(sz.height() + margin);
1766  }
1767 #ifdef Q_WS_X11
1768  }
1769 #endif
1770  if(as_gui_menubar) {
1772  opt.rect = rect();
1773  opt.menuRect = rect();
1774  opt.state = QStyle::State_None;
1777  opt.palette = palette();
1778  return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
1779  ret.expandedTo(QApplication::globalStrut()),
1780  this));
1781  }
1782  return ret;
1783 }
QRect menuRect
the rectangle for the entire menu
Definition: qstyleoption.h:449
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
static QSize globalStrut()
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
int width() const
Returns the width.
Definition: qsize.h:126
bool isNativeMenuBar() const
Definition: qmenubar.cpp:2095
int width() const
const QPalette & palette() const
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QRect rect() const
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
int height() const
Returns the height.
Definition: qsize.h:129
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90

◆ mouseMoveEvent()

void QMenuBar::mouseMoveEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1304 of file qmenubar.cpp.

1305 {
1306  Q_D(QMenuBar);
1307  if (!(e->buttons() & Qt::LeftButton))
1308  d->mouseDown = false;
1309  bool popupState = d->popupState || d->mouseDown;
1310  QAction *action = d->actionAt(e->pos());
1311  if ((action && d->isVisible(action)) || !popupState)
1312  d->setCurrentAction(action, popupState);
1313 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ mousePressEvent()

void QMenuBar::mousePressEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1143 of file qmenubar.cpp.

1144 {
1145  Q_D(QMenuBar);
1146  if(e->button() != Qt::LeftButton)
1147  return;
1148 
1149  d->mouseDown = true;
1150 
1151  QAction *action = d->actionAt(e->pos());
1152  if (!action || !d->isVisible(action)) {
1153  d->setCurrentAction(0);
1154 #ifndef QT_NO_WHATSTHIS
1156  QWhatsThis::showText(e->globalPos(), d->whatsThis, this);
1157 #endif
1158  return;
1159  }
1160 
1161  if(d->currentAction == action && d->popupState) {
1162  if(QMenu *menu = d->activeMenu) {
1163  d->activeMenu = 0;
1164  menu->hide();
1165  }
1166 #ifdef Q_WS_WIN
1167  if((d->closePopupMode = style()->styleHint(QStyle::SH_MenuBar_DismissOnSecondClick)))
1168  update(d->actionRect(action));
1169 #endif
1170  } else {
1171  d->setCurrentAction(action, true);
1172  }
1173 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
const char * styleHint(const QFontDef &request)
static bool inWhatsThisMode()
Returns true if the user interface is in "What&#39;s This?" mode; otherwise returns false.
Definition: qwhatsthis.cpp:648
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What&#39;s This?" window, at global position pos.
Definition: qwhatsthis.cpp:754
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ mouseReleaseEvent()

void QMenuBar::mouseReleaseEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1178 of file qmenubar.cpp.

1179 {
1180  Q_D(QMenuBar);
1181  if(e->button() != Qt::LeftButton || !d->mouseDown)
1182  return;
1183 
1184  d->mouseDown = false;
1185  QAction *action = d->actionAt(e->pos());
1186  if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) {
1187  //we set the current action before activating
1188  //so that we let the leave event set the current back to 0
1189  d->setCurrentAction(action, false);
1190  if(action)
1191  d->activateAction(action, QAction::Trigger);
1192  }
1193  d->closePopupMode = 0;
1194 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ paintEvent()

void QMenuBar::paintEvent ( QPaintEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1068 of file qmenubar.cpp.

1069 {
1070  Q_D(QMenuBar);
1071  QPainter p(this);
1072  QRegion emptyArea(rect());
1073 
1074  //draw the items
1075  for (int i = 0; i < d->actions.count(); ++i) {
1076  QAction *action = d->actions.at(i);
1077  QRect adjustedActionRect = d->actionRect(action);
1078  if (adjustedActionRect.isEmpty() || !d->isVisible(action))
1079  continue;
1080  if(!e->rect().intersects(adjustedActionRect))
1081  continue;
1082 
1083  emptyArea -= adjustedActionRect;
1085  initStyleOption(&opt, action);
1086  opt.rect = adjustedActionRect;
1087  p.setClipRect(adjustedActionRect);
1088  style()->drawControl(QStyle::CE_MenuBarItem, &opt, &p, this);
1089  }
1090  //draw border
1091  if(int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) {
1092  QRegion borderReg;
1093  borderReg += QRect(0, 0, fw, height()); //left
1094  borderReg += QRect(width()-fw, 0, fw, height()); //right
1095  borderReg += QRect(0, 0, width(), fw); //top
1096  borderReg += QRect(0, height()-fw, width(), fw); //bottom
1097  p.setClipRegion(borderReg);
1098  emptyArea -= borderReg;
1099  QStyleOptionFrame frame;
1100  frame.rect = rect();
1101  frame.palette = palette();
1102  frame.state = QStyle::State_None;
1104  frame.midLineWidth = 0;
1105  style()->drawPrimitive(QStyle::PE_PanelMenuBar, &frame, &p, this);
1106  }
1107  p.setClipRegion(emptyArea);
1108  QStyleOptionMenuItem menuOpt;
1109  menuOpt.palette = palette();
1110  menuOpt.state = QStyle::State_None;
1113  menuOpt.rect = rect();
1114  menuOpt.menuRect = rect();
1115  style()->drawControl(QStyle::CE_MenuBarEmptyArea, &menuOpt, &p, this);
1116 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QRect menuRect
the rectangle for the entire menu
Definition: qstyleoption.h:449
double d
Definition: qnumeric_p.h:62
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const
Initialize option with the values from the menu bar and information from action.
Definition: qmenubar.cpp:583
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
QStyle * style() const
Definition: qwidget.cpp:2742
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
int width() const
const QPalette & palette() const
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QRect rect() const
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
int midLineWidth
the mid-line width for drawing the frame
Definition: qstyleoption.h:125
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition: qevent.h:305
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ resizeEvent()

void QMenuBar::resizeEvent ( QResizeEvent )
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1058 of file qmenubar.cpp.

1059 {
1060  Q_D(QMenuBar);
1061  d->itemsDirty = true;
1062  d->updateGeometries();
1063 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ setActiveAction()

void QMenuBar::setActiveAction ( QAction act)

Sets the currently highlighted action to act.

Since
4.1

Definition at line 1002 of file qmenubar.cpp.

Referenced by QAccessibleMenuBar::doAction().

1003 {
1004  Q_D(QMenuBar);
1005  d->setCurrentAction(act, true, false);
1006 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ setCornerWidget()

void QMenuBar::setCornerWidget ( QWidget widget,
Qt::Corner  corner = Qt::TopRightCorner 
)

This sets the given widget to be shown directly on the left of the first menu item, or on the right of the last menu item, depending on corner.

The menu bar takes ownership of widget, reparenting it into the menu bar. However, if the corner already contains a widget, this previous widget will no longer be managed and will still be a visible child of the menu bar.

Note
Using a corner other than Qt::TopRightCorner or Qt::TopLeftCorner will result in a warning.

Definition at line 1980 of file qmenubar.cpp.

Referenced by QMdi::ControlContainer::removeButtonsFromMenuBar(), QMainWindow::setMenuBar(), QMdi::ControlContainer::showButtonsInMenuBar(), and QWorkspacePrivate::showMaximizeControls().

1981 {
1982  Q_D(QMenuBar);
1983  switch (corner) {
1984  case Qt::TopLeftCorner:
1985  if (d->leftWidget)
1986  d->leftWidget->removeEventFilter(this);
1987  d->leftWidget = w;
1988  break;
1989  case Qt::TopRightCorner:
1990  if (d->rightWidget)
1991  d->rightWidget->removeEventFilter(this);
1992  d->rightWidget = w;
1993  break;
1994  default:
1995  qWarning("QMenuBar::setCornerWidget: Only TopLeftCorner and TopRightCorner are supported");
1996  return;
1997  }
1998 
1999 #ifdef Q_WS_X11
2000  if(!d->platformMenuBar->allowCornerWidgets()) {
2001  d->updateCornerWidgetToolBar();
2002  } else {
2003 #endif
2004  if (w) {
2005  w->setParent(this);
2006  w->installEventFilter(this);
2007  }
2008 #ifdef Q_WS_X11
2009  }
2010 #endif
2011 
2012  d->_q_updateLayout();
2013 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ setDefaultAction()

void QMenuBar::setDefaultAction ( QAction act)

Sets the default action to act.

Since
4.4

The default action is assigned to the left soft key. The menu is assigned to the right soft key.

Currently there is only support for the default action on Windows Mobile. On all other platforms this method is not available.

See also
defaultAction()

Definition at line 2126 of file qmenubar.cpp.

Referenced by QDialog::exec().

2127 {
2128  Q_D(QMenuBar);
2129  if (d->defaultAction == act)
2130  return;
2131 #ifdef Q_WS_WINCE
2132  if (qt_wince_is_mobile())
2133  if (d->defaultAction) {
2134  disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));
2135  disconnect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction()));
2136  }
2137 #endif
2138  d->defaultAction = act;
2139 #ifdef Q_WS_WINCE
2140  if (qt_wince_is_mobile())
2141  if (d->defaultAction) {
2142  connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));
2143  connect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction()));
2144  }
2145  if (d->wce_menubar) {
2146  d->wce_menubar->rebuild();
2147  }
2148 #endif
2149 }
double d
Definition: qnumeric_p.h:62
bool qt_wince_is_mobile()
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ setDefaultUp()

void QMenuBar::setDefaultUp ( bool  b)

Definition at line 1043 of file qmenubar.cpp.

1044 {
1045  Q_D(QMenuBar);
1046  d->defaultPopDown = !b;
1047 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ setNativeMenuBar()

void QMenuBar::setNativeMenuBar ( bool  nativeMenuBar)

Definition at line 2062 of file qmenubar.cpp.

2063 {
2064  Q_D(QMenuBar);
2065 #ifdef Q_WS_X11
2066  d->platformMenuBar->setNativeMenuBar(nativeMenuBar);
2067 #else
2068  if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) {
2069  d->nativeMenuBar = nativeMenuBar;
2070 #ifdef Q_WS_MAC
2071  if (!d->nativeMenuBar) {
2072  extern void qt_mac_clear_menubar();
2074  d->macDestroyMenuBar();
2075  const QList<QAction *> &menubarActions = actions();
2076  for (int i = 0; i < menubarActions.size(); ++i) {
2077  const QAction *action = menubarActions.at(i);
2078  if (QMenu *menu = action->menu()) {
2079  delete menu->d_func()->mac_menu;
2080  menu->d_func()->mac_menu = 0;
2081  }
2082  }
2083  } else {
2084  d->macCreateMenuBar(parentWidget());
2085  }
2086  macUpdateMenuBar();
2087  updateGeometry();
2088  if (!d->nativeMenuBar && parentWidget())
2089  setVisible(true);
2090 #endif
2091  }
2092 #endif // Q_WS_X11
2093 }
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
#define Q_D(Class)
Definition: qglobal.h:2482
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
virtual void setVisible(bool visible)
Reimplemented Function
Definition: qmenubar.cpp:1121
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
static bool macUpdateMenuBar()
Definition: qmenu_mac.mm:2055
bool nativeMenuBar
Whether or not a menubar will be used as a native menubar on platforms that support it...
Definition: qmenubar.h:67
void qt_mac_clear_menubar()
Definition: qmenu_mac.mm:2015
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setVisible

void QMenuBar::setVisible ( bool  visible)
virtualslot

Reimplemented Function

Definition at line 1121 of file qmenubar.cpp.

Referenced by setNativeMenuBar().

1122 {
1123 #ifdef Q_WS_X11
1124  Q_D(QMenuBar);
1125  d->platformMenuBar->setVisible(visible);
1126 #else
1127 #if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60)
1128  if (isNativeMenuBar()) {
1129 #ifndef Q_WS_S60
1130  if (!visible)
1131  QWidget::setVisible(false);
1132 #endif
1133  return;
1134  }
1135 #endif
1137 #endif // Q_WS_X11
1138 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isNativeMenuBar() const
Definition: qmenubar.cpp:2095
bool visible
whether the widget is visible
Definition: qwidget.h:191
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ sizeHint()

QSize QMenuBar::sizeHint ( ) const
virtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1788 of file qmenubar.cpp.

1789 {
1790  Q_D(const QMenuBar);
1791 #if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) || defined(Q_WS_X11)
1792  const bool as_gui_menubar = !isNativeMenuBar();
1793 #else
1794  const bool as_gui_menubar = true;
1795 #endif
1796 
1797 
1798  ensurePolished();
1799  QSize ret(0, 0);
1800  const_cast<QMenuBarPrivate*>(d)->updateGeometries();
1801  const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this);
1802  const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
1803  int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
1804  int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
1805  if(as_gui_menubar) {
1806  const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
1807  d->calcActionRects(w - (2 * fw), 0);
1808  for (int i = 0; i < d->actionRects.count(); ++i) {
1809  const QRect &actionRect = d->actionRects.at(i);
1810  ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height()));
1811  }
1812  //the action geometries already contain the top and left
1813  //margins. So we only need to add those from right and bottom.
1814  ret += QSize(fw + hmargin, fw + vmargin);
1815  }
1816  int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
1817 #ifdef Q_WS_X11
1818  if(d->platformMenuBar->allowCornerWidgets()) {
1819 #endif
1820  if(d->leftWidget) {
1821  QSize sz = d->leftWidget->sizeHint();
1822  ret.setWidth(ret.width() + sz.width());
1823  if(sz.height() + margin > ret.height())
1824  ret.setHeight(sz.height() + margin);
1825  }
1826  if(d->rightWidget) {
1827  QSize sz = d->rightWidget->sizeHint();
1828  ret.setWidth(ret.width() + sz.width());
1829  if(sz.height() + margin > ret.height())
1830  ret.setHeight(sz.height() + margin);
1831  }
1832 #ifdef Q_WS_X11
1833  }
1834 #endif
1835  if(as_gui_menubar) {
1837  opt.rect = rect();
1838  opt.menuRect = rect();
1839  opt.state = QStyle::State_None;
1842  opt.palette = palette();
1843  return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
1844  ret.expandedTo(QApplication::globalStrut()),
1845  this));
1846  }
1847  return ret;
1848 }
QRect menuRect
the rectangle for the entire menu
Definition: qstyleoption.h:449
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
static QSize globalStrut()
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
int width() const
Returns the width.
Definition: qsize.h:126
bool isNativeMenuBar() const
Definition: qmenubar.cpp:2095
int width() const
const QPalette & palette() const
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QRect rect() const
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90

◆ timerEvent()

void QMenuBar::timerEvent ( QTimerEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 1393 of file qmenubar.cpp.

1394 {
1395  Q_D(QMenuBar);
1396  if (e->timerId() == d->autoReleaseTimer.timerId()) {
1397  d->autoReleaseTimer.stop();
1398  d->setCurrentAction(0);
1399  }
1401 }
double d
Definition: qnumeric_p.h:62
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
#define Q_D(Class)
Definition: qglobal.h:2482
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62

◆ triggered

void QMenuBar::triggered ( QAction action)
signal

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.

Note
QMenuBar has to have ownership of the QMenu in order this signal to work.

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.

See also
hovered(), QAction::triggered()

Referenced by actionEvent(), QMenuPrivate::activateCausedStack(), addAction(), and defaultAction().

◆ wceCommands()

void QMenuBar::wceCommands ( uint  command)
static

This function sends native Windows CE commands to Qt menu bars and all their child menus.

Warning
This function is not part of the public interface.

Definition at line 313 of file qmenu_wince.cpp.

Referenced by QtWndProc().

314 {
315  const HWND hwndActiveWindow = GetActiveWindow();
316  for (int i = 0; i < nativeMenuBars.size(); ++i) {
317  QMenuBarPrivate* nativeMenuBar = nativeMenuBars.at(i)->d_func();
318  if (hwndActiveWindow == nativeMenuBar->wce_menubar->parentWindowHandle)
319  nativeMenuBar->wceCommands(command);
320  }
321 }
void wceCommands(uint command)
struct QMenuBarPrivate::QWceMenuBarPrivate * wce_menubar
static QList< QMenuBar * > nativeMenuBars
Definition: qmenu_wince.cpp:89
bool nativeMenuBar
Whether or not a menubar will be used as a native menubar on platforms that support it...
Definition: qmenubar.h:67

◆ wceRefresh()

void QMenuBar::wceRefresh ( )
static

This function refreshes the native Windows CE menu.

Warning
This function is not part of the public interface.

Definition at line 277 of file qmenu_wince.cpp.

Referenced by QMenuPrivate::QWceMenuPrivate::rebuild(), QMenuBarPrivate::QWceMenuBarPrivate::syncAction(), wceRefresh(), and QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate().

278 {
279  for (int i = 0; i < nativeMenuBars.size(); ++i)
280  nativeMenuBars.at(i)->d_func()->wceRefresh();
281 }
static QList< QMenuBar * > nativeMenuBars
Definition: qmenu_wince.cpp:89

Friends and Related Functions

◆ QApplicationPrivate

friend class QApplicationPrivate
friend

Definition at line 355 of file qmenubar.h.

◆ QMenu

friend class QMenu
friend

Definition at line 350 of file qmenubar.h.

Referenced by addMenu().

◆ QMenuPrivate

friend class QMenuPrivate
friend

Definition at line 351 of file qmenubar.h.

◆ qt_mac_activate_action

bool qt_mac_activate_action ( MenuRef  menu,
uint  command,
QAction::ActionEvent  action_e,
bool  by_accel 
)
friend

Definition at line 209 of file qmenu_mac.mm.

210 {
211  //fire event
212  QMacMenuAction *action = 0;
213  if (GetMenuCommandProperty(menu, command, kMenuCreatorQt, kMenuPropertyQAction, sizeof(action), 0, &action) != noErr) {
214  QMenuMergeList *list = 0;
215  GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList,
216  sizeof(list), 0, &list);
217  if (!list && qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) {
218  MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu;
219  GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list);
220  if (list)
221  menu = apple_menu;
222  }
223  if (list) {
224  for(int i = 0; i < list->size(); ++i) {
225  QMenuMergeItem item = list->at(i);
226  if (item.command == command && item.action) {
227  action = item.action;
228  break;
229  }
230  }
231  }
232  if (!action)
233  return false;
234  }
235 
236  if (action_e == QAction::Trigger && by_accel && action->ignore_accel) //no, not a real accel (ie tab)
237  return false;
238 
239  // Unhighlight the highlighted menu item before triggering the action to
240  // prevent items from staying highlighted while a modal dialog is shown.
241  // This also fixed the problem that parentless modal dialogs leave
242  // the menu item highlighted (since the menu bar is cleared for these types of dialogs).
243  if (action_e == QAction::Trigger)
244  HiliteMenu(0);
245 
246  action->action->activate(action_e);
247 
248  //now walk up firing for each "caused" widget (like in the platform independent menu)
249  QWidget *caused = 0;
250  if (action_e == QAction::Hover && GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), 0, &caused) == noErr) {
251  MenuRef caused_menu = 0;
252  if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused))
253  caused_menu = qmenu2->macMenu();
254  else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused))
255  caused_menu = qmenubar2->macMenu();
256  else
257  caused_menu = 0;
258  while(caused_menu) {
259  //fire
260  QWidget *widget = 0;
261  GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget);
262  if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) {
263  action->action->showStatusText(widget);
264  emit qmenu->hovered(action->action);
265  } else if (QMenuBar *qmenubar = qobject_cast<QMenuBar*>(widget)) {
266  action->action->showStatusText(widget);
267  emit qmenubar->hovered(action->action);
268  break; //nothing more..
269  }
270 
271  //walk up
272  if (GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget,
273  sizeof(caused), 0, &caused) != noErr)
274  break;
275  if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused))
276  caused_menu = qmenu2->macMenu();
277  else if (QMenuBar *qmenubar2 = qobject_cast<QMenuBar*>(caused))
278  caused_menu = qmenubar2->macMenu();
279  else
280  caused_menu = 0;
281  }
282  }
283  return true;
284 }
uchar ignore_accel
Definition: qmenu_p.h:106
QPointer< QWidget > widget
bool showStatusText(QWidget *widget=0)
Updates the relevant status bar for the widget specified by sending a QStatusTipEvent to its parent w...
Definition: qaction.cpp:1315
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
Definition: qaction.cpp:1326
QMacMenuAction * action
Definition: qmenu_p.h:121
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
MenuCommand command
Definition: qmenu_p.h:116
const UInt32 kMenuCreatorQt
Definition: qmenu_mac.mm:82
static struct @304 qt_mac_current_menubar
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QPointer< QMenuBar > qmenubar
Definition: qmenu_mac.mm:98
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
struct OpaqueMenuRef * MenuRef
QPointer< QAction > action
Definition: qmenu_p.h:108
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void hovered(QAction *action)
This signal is emitted when a menu action is highlighted; action is the action that caused the event ...

◆ QWidgetPrivate

friend class QWidgetPrivate
friend

Definition at line 356 of file qmenubar.h.

◆ QWindowsStyle

friend class QWindowsStyle
friend

Definition at line 352 of file qmenubar.h.

Properties

◆ defaultUp

QMenuBar::defaultUp
private

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.

Definition at line 66 of file qmenubar.h.

◆ nativeMenuBar

QMenuBar::nativeMenuBar
private

Whether or not a menubar will be used as a native menubar on platforms that support it.

Since
4.6

This property specifies whether or not the menubar should be used as a native menubar on platforms that support it. The currently supported platforms are Mac OS X and Windows CE. On these platforms if this property is true, the menubar is used in the native menubar and is not in the window of its parent, if false the menubar remains in the window. On other platforms the value of this attribute has no effect.

The default is to follow whether the Qt::AA_DontUseNativeMenuBar attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.

See also
void-qt-mac-set-native-menubar-bool-enable

Definition at line 67 of file qmenubar.h.

Referenced by actionEvent(), and setNativeMenuBar().


The documentation for this class was generated from the following files: