Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qmenubar.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMENUBAR_H
5#define QMENUBAR_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qmenu.h>
9
11
13
14class QMenuBarPrivate;
16class QWindowsStyle;
18
19class Q_WIDGETS_EXPORT QMenuBar : public QWidget
20{
22
23 Q_PROPERTY(bool defaultUp READ isDefaultUp WRITE setDefaultUp)
24 Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar)
25
26public:
27 explicit QMenuBar(QWidget *parent = nullptr);
28 ~QMenuBar();
29
31#if QT_WIDGETS_REMOVED_SINCE(6, 3)
33 QAction *addAction(const QString &text, const QObject *receiver, const char* member);
34#endif
35
37 QMenu *addMenu(const QString &title);
38 QMenu *addMenu(const QIcon &icon, const QString &title);
39
40
41 QAction *addSeparator();
42 QAction *insertSeparator(QAction *before);
43
44 QAction *insertMenu(QAction *before, QMenu *menu);
45
46 void clear();
47
48 QAction *activeAction() const;
49 void setActiveAction(QAction *action);
50
51 void setDefaultUp(bool);
52 bool isDefaultUp() const;
53
54 QSize sizeHint() const override;
55 QSize minimumSizeHint() const override;
56 int heightForWidth(int) const override;
57
58 QRect actionGeometry(QAction *) const;
59 QAction *actionAt(const QPoint &) const;
60
61 void setCornerWidget(QWidget *w, Qt::Corner corner = Qt::TopRightCorner);
62 QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
63
64#if defined(Q_OS_MACOS) || defined(Q_QDOC)
65 NSMenu* toNSMenu();
66#endif
67
68 bool isNativeMenuBar() const;
69 void setNativeMenuBar(bool nativeMenuBar);
70 QPlatformMenuBar *platformMenuBar();
71public Q_SLOTS:
72 void setVisible(bool visible) override;
73
75 void triggered(QAction *action);
76 void hovered(QAction *action);
77
78protected:
79 void changeEvent(QEvent *) override;
80 void keyPressEvent(QKeyEvent *) override;
81 void mouseReleaseEvent(QMouseEvent *) override;
82 void mousePressEvent(QMouseEvent *) override;
83 void mouseMoveEvent(QMouseEvent *) override;
84 void leaveEvent(QEvent *) override;
85 void paintEvent(QPaintEvent *) override;
86 void resizeEvent(QResizeEvent *) override;
87 void actionEvent(QActionEvent *) override;
88 void focusOutEvent(QFocusEvent *) override;
89 void focusInEvent(QFocusEvent *) override;
90 void timerEvent(QTimerEvent *) override;
91 bool eventFilter(QObject *, QEvent *) override;
92 bool event(QEvent *) override;
93 virtual void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const;
94
95private:
96 Q_DECLARE_PRIVATE(QMenuBar)
97 Q_DISABLE_COPY(QMenuBar)
98 Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())
99 Q_PRIVATE_SLOT(d_func(), void _q_actionHovered())
100 Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int))
101 Q_PRIVATE_SLOT(d_func(), void _q_updateLayout())
102
103 friend class QMenu;
104 friend class QMenuPrivate;
105 friend class QWindowsStyle;
106};
107
109
110#endif // QMENUBAR_H
The QActionEvent class provides an event that is generated when a QAction is added,...
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
\inmodule QtCore
Definition qcoreevent.h:45
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
The QKeyEvent class describes a key event.
Definition qevent.h:423
The QMenuBar class provides a horizontal menu bar.
Definition qmenubar.h:20
void hovered(QAction *action)
This signal is emitted when a menu action is highlighted; action is the action that caused the event ...
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 QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtGui
Definition qevent.h:195
\inmodule QtCore
Definition qobject.h:90
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
Definition qobject.cpp:1518
virtual void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object.
Definition qobject.cpp:1433
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:30
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\variable QStyleOptionProgressBar::minimum
\inmodule QtCore
Definition qcoreevent.h:359
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
virtual void leaveEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition qwidget.cpp:9777
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition qwidget.cpp:9507
virtual void actionEvent(QActionEvent *event)
This event handler is called with the given event whenever the widget's actions are changed.
Definition qwidget.cpp:9881
virtual void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition qwidget.cpp:9529
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9711
virtual void mouseReleaseEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition qwidget.cpp:9554
QSize minimumSizeHint
the recommended minimum size for the widget
Definition qwidget.h:149
virtual void setVisible(bool visible)
Definition qwidget.cpp:8329
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9428
QSize sizeHint
the recommended size for the widget
Definition qwidget.h:148
virtual void focusOutEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition qwidget.cpp:9737
virtual void resizeEvent(QResizeEvent *event)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition qwidget.cpp:9868
virtual void keyPressEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition qwidget.cpp:9652
virtual void paintEvent(QPaintEvent *event)
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Definition qwidget.cpp:9829
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3124
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
b clear()
QString text
Combined button and popup list for selecting options.
@ TopRightCorner
GLfloat GLfloat GLfloat w
[0]
struct _cl_event * event
GLuint GLenum option
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
QString title
[35]
QMenu menu
[5]
menubar addMenu(fileMenu)
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent