QMenu Class
QMenu 提供一个用于菜单栏, 上下文菜单和其他弹出菜单. 更多...
头文件: | #include <QMenu> |
qmake: | QT += widgets |
基类: | QWidget |
属性
|
|
公有函数
QMenu(QWidget *parent = Q_NULLPTR) | |
QMenu(const QString &title, QWidget *parent = Q_NULLPTR) | |
~QMenu() | |
QAction * | actionAt(const QPoint &pt) const |
QRect | actionGeometry(QAction *act) const |
QAction * | activeAction() const |
QAction * | addAction(const QString &text) |
QAction * | addAction(const QIcon &icon, const QString &text) |
QAction * | addAction(const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut = 0) |
QAction * | addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut = 0) |
QAction * | addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) |
QAction * | addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0) |
QAction * | addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0) |
QAction * | addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) |
QAction * | addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0) |
QAction * | addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0) |
QAction * | addMenu(QMenu *menu) |
QMenu * | addMenu(const QString &title) |
QMenu * | addMenu(const QIcon &icon, const QString &title) |
QAction * | addSection(const QString &text) |
QAction * | addSection(const QIcon &icon, const QString &text) |
QAction * | addSeparator() |
void | clear() |
QAction * | defaultAction() const |
QAction * | exec() |
QAction * | exec(const QPoint &p, QAction *action = Q_NULLPTR) |
void | hideTearOffMenu() |
QIcon | icon() const |
QAction * | insertMenu(QAction *before, QMenu *menu) |
QAction * | insertSection(QAction *before, const QString &text) |
QAction * | insertSection(QAction *before, const QIcon &icon, const QString &text) |
QAction * | insertSeparator(QAction *before) |
bool | isEmpty() const |
bool | isTearOffEnabled() const |
bool | isTearOffMenuVisible() const |
QAction * | menuAction() const |
void | popup(const QPoint &p, QAction *atAction = Q_NULLPTR) |
bool | separatorsCollapsible() const |
void | setActiveAction(QAction *act) |
void | setAsDockMenu() |
void | setDefaultAction(QAction *act) |
void | setIcon(const QIcon &icon) |
void | setSeparatorsCollapsible(bool collapse) |
void | setTearOffEnabled(bool) |
void | setTitle(const QString &title) |
void | setToolTipsVisible(bool visible) |
void | showTearOffMenu(const QPoint &pos) |
void | showTearOffMenu() |
QString | title() const |
NSMenu * | toNSMenu() |
bool | toolTipsVisible() const |
重新实现的公有函数
virtual QSize | sizeHint() const |
- 214 个公有函数继承自 QWidget
- 32 个公有函数继承自 QObject
- 14 个公有函数继承自 QPaintDevice
信号
void | aboutToHide() |
void | aboutToShow() |
void | hovered(QAction *action) |
void | triggered(QAction *action) |
静态公有成员
QAction * | exec(QList<QAction *> actions, const QPoint &pos, QAction *at = Q_NULLPTR, QWidget *parent = Q_NULLPTR) |
受保护的函数
int | columnCount() const |
void | initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const |
重新实现的受保护函数
virtual void | actionEvent(QActionEvent *e) |
virtual void | changeEvent(QEvent *e) |
virtual void | enterEvent(QEvent *) |
virtual bool | event(QEvent *e) |
virtual bool | focusNextPrevChild(bool next) |
virtual void | hideEvent(QHideEvent *) |
virtual void | keyPressEvent(QKeyEvent *e) |
virtual void | leaveEvent(QEvent *) |
virtual void | mouseMoveEvent(QMouseEvent *e) |
virtual void | mousePressEvent(QMouseEvent *e) |
virtual void | mouseReleaseEvent(QMouseEvent *e) |
virtual void | paintEvent(QPaintEvent *e) |
virtual void | timerEvent(QTimerEvent *e) |
virtual void | wheelEvent(QWheelEvent *e) |
- 35 个受保护的函数继承自 QWidget
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QPaintDevice
其他继承的成员
- 19 个公有槽函数继承自 QWidget
- 1 个公有槽函数继承自 QObject
- 1 个公有变量继承自 QObject
- 1 个受保护的槽函数继承自 QWidget
- 2 个受保护的变量继承自 QObject
- 1 protected type inherited from QPaintDevice
详细描述
QMenu 提供一个用于菜单栏, 上下文菜单和其他弹出菜单.
用户点击菜单栏的选项或按指定快捷键时, 显示下拉菜单. 调用 QMenuBar::addMenu() 将菜单插入菜单栏. 上下文菜单通常由键盘按键或鼠标右击触发. 菜单可调用 popup() 异步执行, 也可调用 exec()同步执行. 菜单也可由按钮按下触发; 除调用方式外, 与上下文菜单一样.
![]() | ![]() | ![]() |
Fig. A menu shown in Fusion widget style, Windows XP widget style, and Macintosh widget style.
Actions
菜单由一系列动作列表组成. 调用 addAction(), addActions() 和 insertAction() 添加执行动作. 动作列表垂直排列, 并由 QStyle 控制外观. 此外, 动作有文本, 左侧可选图标和快捷键"Ctrl+X".
调用 actions()获取菜单现有动作.
菜单有四种动作类型: 分隔符, 子菜单, widget, 执行动作. 调用 addSeparator()插入分隔符, 调用 addMenu()插入子菜单, 其他类型是执行动作项.
插入动作时, 你需要关联接收者和槽函数. 动作触发时, 接收者收到信号 triggered(). 此外, QMenu 提供两个信号: triggered() 和 hovered(), 这两个信号由菜单的 QAction 触发.
你可以调用 clear() 清除菜单动作项, 调用 removeAction()单个动作项.
QMenu 也提供分离式菜单. 分离式菜单是复制菜单的顶层窗口, 这使得用户可以 "分离" 使用频次较高的菜单. 如果你想将这个功能应用于某个菜单, 你可以调用 setTearOffEnabled(). 由于Windows操作系统的用户不熟悉分离式菜单时, 建议使用 QToolBar 替代.
各类widget可以利用 QWidgetAction 类插入菜单. 这个类实例控制widget, 并利用QAction的 addAction() 重载函数插入菜单.
反过来, 调用widget的 addAction(), addActions(), insertAction() 函数可以为其增加动作.
警告: 要使 QMenu 在屏幕显示, 应调用exec() 或 popup(), 而不是 show().
在macOS上, Qt基于Cocoa构建QMenu
QMenu 只能在菜单/菜单栏插入一次. 后续插入无效或导致菜单项禁用.
Menus 示例展示如何在应用程序中使用 QMenuBar 和 QMenu.
重要的继承函数: addAction(), removeAction(), clear(), addSeparator(), addMenu().
参见 QMenuBar, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Application Example, Menus Example.
属性
icon : QIcon
This property holds the icon of the menu
This is equivalent to the QAction::icon property of the menuAction().
By default, if no icon is explicitly set, this property contains a null icon.
访问函数:
QIcon | icon() const |
void | setIcon(const QIcon &icon) |
separatorsCollapsible : bool
This property holds whether consecutive separators should be collapsed
This property specifies whether consecutive separators in the menu should be visually collapsed to a single one. Separators at the beginning or the end of the menu are also hidden.
By default, this property is true
.
This property was introduced in Qt 4.2.
访问函数:
bool | separatorsCollapsible() const |
void | setSeparatorsCollapsible(bool collapse) |
tearOffEnabled : bool
This property holds whether the menu supports being torn off
When true, the menu contains a special tear-off item (often shown as a dashed line at the top of the menu) that creates a copy of the menu when it is triggered.
This "torn-off" copy lives in a separate window. It contains the same menu items as the original menu, with the exception of the tear-off handle.
By default, this property is false
.
访问函数:
bool | isTearOffEnabled() const |
void | setTearOffEnabled(bool) |
title : QString
This property holds the title of the menu
This is equivalent to the QAction::text property of the menuAction().
By default, this property contains an empty string.
访问函数:
QString | title() const |
void | setTitle(const QString &title) |
toolTipsVisible : bool
This property holds whether tooltips of menu actions should be visible
This property specifies whether action menu entries show their tooltip.
By default, this property is false
.
This property was introduced in Qt 5.1.
访问函数:
bool | toolTipsVisible() const |
void | setToolTipsVisible(bool visible) |
成员函数
QMenu::QMenu(QWidget *parent = Q_NULLPTR)
Constructs a menu with parent parent.
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject).
QMenu::QMenu(const QString &title, QWidget *parent = Q_NULLPTR)
Constructs a menu with a title and a parent.
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject).
参见 title.
QMenu::~QMenu()
Destroys the menu.
[signal]
void QMenu::aboutToHide()
This signal is emitted just before the menu is hidden from the user.
This function was introduced in Qt 4.2.
参见 aboutToShow() and hide().
[signal]
void QMenu::aboutToShow()
This signal is emitted just before the menu is shown to the user.
参见 aboutToHide() and show().
QAction *QMenu::actionAt(const QPoint &pt) const
Returns the item at pt; returns 0 if there is no item there.
[virtual protected]
void QMenu::actionEvent(QActionEvent *e)
重新实现 QWidget::actionEvent().
QRect QMenu::actionGeometry(QAction *act) const
Returns the geometry of action act.
QAction *QMenu::activeAction() const
Returns the currently highlighted action, or 0 if no action is currently highlighted.
参见 setActiveAction().
QAction *QMenu::addAction(const QString &text)
This is an overloaded function.
This convenience function creates a new action with text. The function adds the newly created action to the menu's list of actions, and returns it.
QMenu takes ownership of the returned QAction.
参见 QWidget::addAction().
QAction *QMenu::addAction(const QIcon &icon, const QString &text)
This is an overloaded function.
This convenience function creates a new action with an icon and some text. The function adds the newly created action to the menu's list of actions, and returns it.
QMenu takes ownership of the returned QAction.
参见 QWidget::addAction().
QAction *QMenu::addAction(const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with the text text and an optional shortcut shortcut. 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.
QMenu takes ownership of the returned QAction.
参见 QWidget::addAction().
QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with an icon and some text and an optional shortcut shortcut. The action's triggered() signal is connected to the member slot of the receiver object. The function adds the newly created action to the menu's list of actions, and returns it.
QMenu takes ownership of the returned QAction.
参见 QWidget::addAction().
QAction *QMenu::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with the text text and an optional shortcut shortcut. The action's triggered() signal is connected to the method of the receiver. The function adds the newly created action to the menu's list of actions and returns it.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.6.
QAction *QMenu::addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with the text text and an optional shortcut shortcut. The action's triggered() signal is connected to the functor. The function adds the newly created action to the menu's list of actions and returns it.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.6.
QAction *QMenu::addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with the text text and an optional shortcut shortcut. The action's triggered() signal is connected to the functor. The function adds the newly created action to the menu's list of actions and returns it.
If context is destroyed, the functor will not be called.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.6.
QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with an icon and some text and an optional shortcut shortcut. The action's triggered() signal is connected to the method of the receiver. The function adds the newly created action to the menu's list of actions and returns it.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.6.
QAction *QMenu::addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with an icon and some text and an optional shortcut shortcut. The action's triggered() signal is connected to the functor. The function adds the newly created action to the menu's list of actions and returns it.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.6.
QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0)
This is an overloaded function.
This convenience function creates a new action with an icon and some text and an optional shortcut shortcut. The action's triggered() signal is connected to the functor. The function adds the newly created action to the menu's list of actions and returns it.
If context is destroyed, the functor will not be called.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.6.
QAction *QMenu::addMenu(QMenu *menu)
This convenience function adds menu as a submenu to this menu. It returns menu's menuAction(). This menu does not take ownership of menu.
参见 QWidget::addAction() and QMenu::menuAction().
QMenu *QMenu::addMenu(const QString &title)
Appends a new QMenu with title to the menu. The menu takes ownership of the menu. Returns the new menu.
参见 QWidget::addAction() and QMenu::menuAction().
QMenu *QMenu::addMenu(const QIcon &icon, const QString &title)
Appends a new QMenu with icon and title to the menu. The menu takes ownership of the menu. Returns the new menu.
参见 QWidget::addAction() and QMenu::menuAction().
QAction *QMenu::addSection(const QString &text)
This convenience function creates a new section action, i.e. an action with QAction::isSeparator() returning true but also having text hint, and adds the new action to this menu's list of actions. It returns the newly created action.
The rendering of the hint is style and platform dependent. Widget styles can use the text information in the rendering for sections, or can choose to ignore it and render sections like simple separators.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.1.
参见 QWidget::addAction().
QAction *QMenu::addSection(const QIcon &icon, const QString &text)
This convenience function creates a new section action, i.e. an action with QAction::isSeparator() returning true but also having text and icon hints, and adds the new action to this menu's list of actions. It returns the newly created action.
The rendering of the hints is style and platform dependent. Widget styles can use the text and icon information in the rendering for sections, or can choose to ignore them and render sections like simple separators.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.1.
参见 QWidget::addAction().
QAction *QMenu::addSeparator()
This convenience function creates a new separator action, i.e. an action with QAction::isSeparator() returning true, and adds the new action to this menu's list of actions. It returns the newly created action.
QMenu takes ownership of the returned QAction.
参见 QWidget::addAction().
[virtual protected]
void QMenu::changeEvent(QEvent *e)
重新实现 QWidget::changeEvent().
void QMenu::clear()
Removes all the menu's actions. Actions owned by the menu and not shown in any other widget are deleted.
参见 removeAction().
[protected]
int QMenu::columnCount() const
If a menu does not fit on the screen it lays itself out so that it does fit. It is style dependent what layout means (for example, on Windows it will use multiple columns).
This functions returns the number of columns necessary.
QAction *QMenu::defaultAction() const
Returns the current default action.
参见 setDefaultAction().
[virtual protected]
void QMenu::enterEvent(QEvent *)
重新实现 QWidget::enterEvent().
[virtual protected]
bool QMenu::event(QEvent *e)
重新实现 QObject::event().
QAction *QMenu::exec()
Executes this menu synchronously.
This is equivalent to exec(pos())
.
This returns the triggered QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
In most situations you'll want to specify the position yourself, for example, the current mouse position:
exec(QCursor::pos());
or aligned to a widget:
exec(somewidget.mapToGlobal(QPoint(0,0)));
or in reaction to a QMouseEvent *e:
exec(e->globalPos());
QAction *QMenu::exec(const QPoint &p, QAction *action = Q_NULLPTR)
This is an overloaded function.
Executes this menu synchronously.
Pops up the menu so that the action action will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().
This returns the triggered QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
Note that all signals are emitted as usual. If you connect a QAction to a slot and call the menu's exec(), you get the result both via the signal-slot connection and in the return value of exec().
Common usage is to position the menu at the current mouse position:
exec(QCursor::pos());
or aligned to a widget:
exec(somewidget.mapToGlobal(QPoint(0, 0)));
or in reaction to a QMouseEvent *e:
exec(e->globalPos());
When positioning a menu with exec() or popup(), bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint() which calculates the proper size depending on the menu's current contents.
参见 popup() and QWidget::mapToGlobal().
[static]
QAction *QMenu::exec(QList<QAction *> actions, const QPoint &pos, QAction *at = Q_NULLPTR, QWidget *parent = Q_NULLPTR)
This is an overloaded function.
Executes a menu synchronously.
The menu's actions are specified by the list of actions. The menu will pop up so that the specified action, at, appears at global position pos. If at is not specified then the menu appears at position pos. parent is the menu's parent widget; specifying the parent will provide context when pos alone is not enough to decide where the menu should go (e.g., with multiple desktops or when the parent is embedded in QGraphicsView).
The function returns the triggered QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
This is equivalent to:
QMenu menu; QAction *at = actions[0]; // Assumes actions is not empty foreach (QAction *a, actions) menu.addAction(a); menu.exec(pos, at);
参见 popup() and QWidget::mapToGlobal().
[virtual protected]
bool QMenu::focusNextPrevChild(bool next)
重新实现 QWidget::focusNextPrevChild().
[virtual protected]
void QMenu::hideEvent(QHideEvent *)
重新实现 QWidget::hideEvent().
void QMenu::hideTearOffMenu()
This function will forcibly hide the torn off menu making it disappear from the user's desktop.
参见 showTearOffMenu(), isTearOffMenuVisible(), and isTearOffEnabled().
[signal]
void QMenu::hovered(QAction *action)
This signal is emitted when a menu action is highlighted; action is the action that caused the signal to be emitted.
Often this is used to update status information.
参见 triggered() and QAction::hovered().
[protected]
void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const
Initialize option with the values from this menu 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.
参见 QStyleOption::initFrom() and QMenuBar::initStyleOption().
QAction *QMenu::insertMenu(QAction *before, QMenu *menu)
This convenience function inserts menu before action before and returns the menus menuAction().
参见 QWidget::insertAction() and addMenu().
QAction *QMenu::insertSection(QAction *before, const QString &text)
This convenience function creates a new title action, i.e. an action with QAction::isSeparator() returning true but also having text hint. The function inserts the newly created action into this menu's list of actions before action before and returns it.
The rendering of the hint is style and platform dependent. Widget styles can use the text information in the rendering for sections, or can choose to ignore it and render sections like simple separators.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.1.
参见 QWidget::insertAction() and addSection().
QAction *QMenu::insertSection(QAction *before, const QIcon &icon, const QString &text)
This convenience function creates a new title action, i.e. an action with QAction::isSeparator() returning true but also having text and icon hints. The function inserts the newly created action into this menu's list of actions before action before and returns it.
The rendering of the hints is style and platform dependent. Widget styles can use the text and icon information in the rendering for sections, or can choose to ignore them and render sections like simple separators.
QMenu takes ownership of the returned QAction.
This function was introduced in Qt 5.1.
参见 QWidget::insertAction() and addSection().
QAction *QMenu::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's list of actions before action before and returns it.
QMenu takes ownership of the returned QAction.
参见 QWidget::insertAction() and addSeparator().
bool QMenu::isEmpty() const
Returns true
if there are no visible actions inserted into the menu, false otherwise.
This function was introduced in Qt 4.2.
参见 QWidget::actions().
bool QMenu::isTearOffMenuVisible() const
When a menu is torn off a second menu is shown to display the menu contents in a new window. When the menu is in this mode and the menu is visible returns true
; otherwise false.
参见 showTearOffMenu(), hideTearOffMenu(), and isTearOffEnabled().
[virtual protected]
void QMenu::keyPressEvent(QKeyEvent *e)
重新实现 QWidget::keyPressEvent().
[virtual protected]
void QMenu::leaveEvent(QEvent *)
重新实现 QWidget::leaveEvent().
QAction *QMenu::menuAction() const
Returns the action associated with this menu.
[virtual protected]
void QMenu::mouseMoveEvent(QMouseEvent *e)
重新实现 QWidget::mouseMoveEvent().
[virtual protected]
void QMenu::mousePressEvent(QMouseEvent *e)
重新实现 QWidget::mousePressEvent().
[virtual protected]
void QMenu::mouseReleaseEvent(QMouseEvent *e)
重新实现 QWidget::mouseReleaseEvent().
[virtual protected]
void QMenu::paintEvent(QPaintEvent *e)
重新实现 QWidget::paintEvent().
void QMenu::popup(const QPoint &p, QAction *atAction = Q_NULLPTR)
Displays the menu so that the action atAction will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().
When positioning a menu with exec() or popup(), bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary, so in many cases, the size before and after the show is different. Instead, use sizeHint() which calculates the proper size depending on the menu's current contents.
参见 QWidget::mapToGlobal() and exec().
void QMenu::setActiveAction(QAction *act)
Sets the currently highlighted action to act.
参见 activeAction().
void QMenu::setAsDockMenu()
Set this menu to be the dock menu available by option-clicking on the application dock icon. Available on macOS only.
This function was introduced in Qt 5.2.
void QMenu::setDefaultAction(QAction *act)
This sets the default action to act. The default action may have a visual cue, depending on the current QStyle. A default action usually indicates what will happen by default when a drop occurs.
参见 defaultAction().
void QMenu::showTearOffMenu(const QPoint &pos)
This function will forcibly show the torn off menu making it appear on the user's desktop at the specified global position pos.
This function was introduced in Qt 5.7.
参见 hideTearOffMenu(), isTearOffMenuVisible(), and isTearOffEnabled().
void QMenu::showTearOffMenu()
This is an overloaded function.
This function will forcibly show the torn off menu making it appear on the user's desktop under the mouse currsor.
This function was introduced in Qt 5.7.
参见 hideTearOffMenu(), isTearOffMenuVisible(), and isTearOffEnabled().
[virtual]
QSize QMenu::sizeHint() const
重新实现 QWidget::sizeHint().
[virtual protected]
void QMenu::timerEvent(QTimerEvent *e)
重新实现 QObject::timerEvent().
NSMenu *QMenu::toNSMenu()
Returns the native NSMenu for this menu. Available on macOS only.
Note: Qt sets the delegate on the native menu. If you need to set your own delegate, make sure you save the original one and forward any calls to it.
This function was introduced in Qt 5.2.
[signal]
void QMenu::triggered(QAction *action)
This signal is emitted when an action in this menu is triggered.
action is the action that caused the signal to be emitted.
Normally, you connect each menu action's triggered() signal to its own custom slot, but sometimes you will want to connect several actions to a single slot, for example, when you have a group of closely related actions, such as "left justify", "center", "right justify".
Note: This signal is emitted for the main parent menu in a hierarchy. Hence, only the parent menu needs to be connected to a slot; sub-menus need not be connected.
参见 hovered() and QAction::triggered().
[virtual protected]
void QMenu::wheelEvent(QWheelEvent *e)
重新实现 QWidget::wheelEvent().