QMenu 类

QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus. 更多...

头: #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

信号

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 )

额外继承成员

详细描述

QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.

菜单 Widget 是选择菜单。它可以是菜单栏中的下拉菜单 (或独立上下文菜单)。下拉菜单通过菜单栏展示当用户点击各项 (或按下指定快捷键) 时。使用 QMenuBar::addMenu () 以将菜单插入菜单栏。上下文菜单通常通过一些特殊键盘键 (或右键点击) 援引。可以异步执行它们采用 popup () 或同步采用 exec ()。菜单也可以为响应按钮按下被援引;这些就像上下文菜单,除如何援引它们外。

动作

A menu consists of a list of action items. Actions are added with the addAction (), addActions () 和 insertAction () functions. An action is represented vertically and rendered by QStyle . In addition, actions can have a text label, an optional icon drawn on the very left side, and shortcut key sequence such as "Ctrl+X".

The existing actions held by a menu can be found with actions ().

There are four kinds of action items: separators, actions that show a submenu, widgets, and actions that perform an action. Separators are inserted with addSeparator (), submenus with addMenu (), and all other items are considered action items.

When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is triggered() . In addition, QMenu provides two signals, triggered () 和 hovered (), which signal the QAction that was triggered from the menu.

清零菜单采用 clear () 和移除单个动作项采用 removeAction ().

A QMenu can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to "tear off" frequently used menus and position them in a convenient place on the screen. If you want this functionality for a particular menu, insert a tear-off handle with setTearOffEnabled ()。当使用撕离菜单时,请记住此概念通常不用于 Microsoft Windows,因此某些用户可能对它不熟悉。考虑使用 QToolBar 代替。

可以将 Widget 插入菜单采用 QWidgetAction class. Instances of this class are used to hold widgets, and are inserted into menus with the addAction () overload that takes a QAction .

Conversely, actions can be added to widgets with the addAction (), addActions () 和 insertAction () 函数。

警告: To make QMenu visible on the screen, exec () 或 popup () 应该被使用而非 show ().

在 macOS 采用 Qt 构建针对 Cocoa 的 QMenu

QMenu can be inserted only once in a menu/menubar. Subsequent insertions will have no effect or will result in a disabled menu item.

菜单 范例,了解如何使用 QMenuBar and QMenu 在应用程序中。

重要继承函数: addAction (), removeAction (), clear (), addSeparator (),和 addMenu ().

另请参阅 QMenuBar , GUI 设计手册:菜单、下拉及弹出 , 应用程序范例 ,和 菜单范例 .

特性文档编制

icon : QIcon

此特性保持菜单的图标

这相当于 QAction::icon 特性为 menuAction ().

默认情况下,若未明确设置图标,此特性包含 null 图标。

访问函数:

QIcon icon () const
void setIcon (const QIcon & icon )

separatorsCollapsible : bool

此特性保持连续分隔符是否应该被折叠

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.

默认情况下此特性为 true .

该特性在 Qt 4.2 引入。

访问函数:

bool separatorsCollapsible () const
void setSeparatorsCollapsible (bool collapse )

tearOffEnabled : bool

此特性保持菜单是否支持被撕离

当为 true 时,菜单包含特殊可撕离项 (经常在菜单顶部展示成虚线),当触发它时会创建菜单副本。

此撕离副本活在单独窗口中。它包含如原始菜单的相同菜单项,除具有可撕离手柄外。

默认情况下此特性为 false .

访问函数:

bool isTearOffEnabled () const
void setTearOffEnabled ( bool )

title : QString

此特性保持菜单的标题

这相当于 QAction::text 特性为 menuAction ().

默认情况下,此特性包含空字符串。

访问函数:

QString title () const
void setTitle (const QString & title )

toolTipsVisible : bool

此特性保持菜单动作的工具提示是否应可见

This property specifies whether action menu entries show their tooltip.

默认情况下此特性为 false .

该特性在 Qt 5.1 引入。

访问函数:

bool toolTipsVisible () const
void setToolTipsVisible (bool visible )

成员函数文档编制

QMenu:: QMenu ( QWidget * parent = Q_NULLPTR)

构造菜单采用父级 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)

构造菜单采用 title 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 ()

销毁菜单。

[signal] void QMenu:: aboutToHide ()

此信号被发射仅仅在菜单对用户隐藏之前。

该函数在 Qt 4.2 引入。

另请参阅 aboutToShow () 和 hide ().

[signal] void QMenu:: aboutToShow ()

此信号被发射仅仅在菜单对用户展示之前。

另请参阅 aboutToHide () 和 show ().

QAction *QMenu:: actionAt (const QPoint & pt ) const

返回项在 pt ; returns 0 if there is no item there.

[virtual protected] void QMenu:: actionEvent ( QActionEvent * e )

重实现自 QWidget::actionEvent ().

QRect QMenu:: actionGeometry ( QAction * act ) const

返回几何体对于动作 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 )

这是重载函数。

此方便函数创建新动作,采用 text 。函数将新近创建的动作添加到菜单的动作列表,并返回它。

QMenu 拥有所有权对于返回的 QAction .

另请参阅 QWidget::addAction ().

QAction *QMenu:: addAction (const QIcon & icon , const QString & text )

这是重载函数。

This convenience function creates a new action with an icon 和一些 text 。函数将新近创建的动作添加到菜单的动作列表,并返回它。

QMenu 拥有所有权对于返回的 QAction .

另请参阅 QWidget::addAction ().

QAction *QMenu:: addAction (const QString & text , const QObject * receiver , const char * member , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with the text text and an optional shortcut shortcut 。动作的 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 拥有所有权对于返回的 QAction .

另请参阅 QWidget::addAction ().

QAction *QMenu:: addAction (const QIcon & icon , const QString & text , const QObject * receiver , const char * member , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with an icon 和一些 text and an optional shortcut shortcut 。动作的 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 拥有所有权对于返回的 QAction .

另请参阅 QWidget::addAction ().

QAction *QMenu:: addAction (const QString & text , const QObject * receiver , PointerToMemberFunction method , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with the text text and an optional shortcut shortcut 。动作的 triggered() signal is connected to the method receiver . The function adds the newly created action to the menu's list of actions and returns it.

QMenu 拥有所有权对于返回的 QAction .

该函数在 Qt 5.6 引入。

QAction *QMenu:: addAction (const QString & text , Functor functor , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with the text text and an optional shortcut shortcut 。动作的 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 拥有所有权对于返回的 QAction .

该函数在 Qt 5.6 引入。

QAction *QMenu:: addAction (const QString & text , const QObject * context , Functor functor , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with the text text and an optional shortcut shortcut 。动作的 triggered() signal is connected to the functor . The function adds the newly created action to the menu's list of actions and returns it.

context is destroyed, the functor will not be called.

QMenu 拥有所有权对于返回的 QAction .

该函数在 Qt 5.6 引入。

QAction *QMenu:: addAction (const QIcon & icon , const QString & text , const QObject * receiver , PointerToMemberFunction method , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with an icon 和一些 text and an optional shortcut shortcut 。动作的 triggered() signal is connected to the method receiver . The function adds the newly created action to the menu's list of actions and returns it.

QMenu 拥有所有权对于返回的 QAction .

该函数在 Qt 5.6 引入。

QAction *QMenu:: addAction (const QIcon & icon , const QString & text , Functor functor , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with an icon 和一些 text and an optional shortcut shortcut 。动作的 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 拥有所有权对于返回的 QAction .

该函数在 Qt 5.6 引入。

QAction *QMenu:: addAction (const QIcon & icon , const QString & text , const QObject * context , Functor functor , const QKeySequence & shortcut = 0)

这是重载函数。

This convenience function creates a new action with an icon 和一些 text and an optional shortcut shortcut 。动作的 triggered() signal is connected to the functor . The function adds the newly created action to the menu's list of actions and returns it.

context is destroyed, the functor will not be called.

QMenu 拥有所有权对于返回的 QAction .

该函数在 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 () 和 QMenu::menuAction ().

QMenu *QMenu:: addMenu (const QString & title )

追加新的 QMenu with title to the menu. The menu takes ownership of the menu. Returns the new menu.

另请参阅 QWidget::addAction () 和 QMenu::menuAction ().

QMenu *QMenu:: addMenu (const QIcon & icon , const QString & title )

追加新的 QMenu with icon and title to the menu. The menu takes ownership of the menu. Returns the new menu.

另请参阅 QWidget::addAction () 和 QMenu::menuAction ().

QAction *QMenu:: addSection (const QString & text )

此方便函数创建新的区间动作,即动作采用 QAction::isSeparator () 返回 true,但还有 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 拥有所有权对于返回的 QAction .

该函数在 Qt 5.1 引入。

另请参阅 QWidget::addAction ().

QAction *QMenu:: addSection (const QIcon & icon , const QString & text )

此方便函数创建新的区间动作,即动作采用 QAction::isSeparator () 返回 true,但还有 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 拥有所有权对于返回的 QAction .

该函数在 Qt 5.1 引入。

另请参阅 QWidget::addAction ().

QAction *QMenu:: addSeparator ()

此方便函数创建新分隔符动作,即:动作采用 QAction::isSeparator () 返回 true,并将新动作添加到此菜单的动作列表。它返回新近创建动作。

QMenu 拥有所有权对于返回的 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

返回当前默认操作。

另请参阅 setDefaultAction ().

[virtual protected] void QMenu:: enterEvent ( QEvent * )

重实现自 QWidget::enterEvent ().

[virtual protected] bool QMenu:: event ( QEvent * e )

重实现自 QObject::event ().

QAction *QMenu:: exec ()

同步执行此菜单。

这相当于 exec(pos()) .

这返回被触发 QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).

在大多数状况下,想要自己指定位置,例如,当前鼠标位置:

exec(QCursor::pos());
					

或对齐 Widget:

exec(somewidget.mapToGlobal(QPoint(0,0)));
					

或反应 QMouseEvent *e:

exec(e->globalPos());
					

QAction *QMenu:: exec (const QPoint & p , QAction * action = Q_NULLPTR)

这是重载函数。

同步执行此菜单。

弹出菜单以便动作 action 将在指定 global 位置 p . To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal ().

这返回被触发 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());
					

或对齐 Widget:

exec(somewidget.mapToGlobal(QPoint(0, 0)));
					

或反应 QMouseEvent *e:

exec(e->globalPos());
					

When positioning a menu with exec () 或 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 () 和 QWidget::mapToGlobal ().

[static] QAction *QMenu:: exec ( QList < QAction *> actions , const QPoint & pos , QAction * at = Q_NULLPTR, QWidget * parent = Q_NULLPTR)

这是重载函数。

同步执行菜单。

指定菜单的动作通过 actions 列表。菜单将弹出以便指定动作 at ,出现在全局位置 pos 。若 at 未指定,则菜单出现在位置 pos . parent 是菜单的父级 Widget;指定父级将提供上下文当 pos 单凭这不足以决定菜单应该放在哪里 (如:具有多个桌面或父级被嵌入 QGraphicsView ).

函数返回被触发 QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).

这相当于:

QMenu menu;
QAction *at = actions[0]; // Assumes actions is not empty
foreach (QAction *a, actions)
    menu.addAction(a);
menu.exec(pos, at);
					

另请参阅 popup () 和 QWidget::mapToGlobal ().

[virtual protected] bool QMenu:: focusNextPrevChild ( bool next )

重实现自 QWidget::focusNextPrevChild ().

[virtual protected] void QMenu:: hideEvent ( QHideEvent * )

重实现自 QWidget::hideEvent ().

void QMenu:: hideTearOffMenu ()

此函数将强制隐藏撕离菜单,使之从用户桌面消失。

另请参阅 showTearOffMenu (), isTearOffMenuVisible (),和 isTearOffEnabled ().

[signal] void QMenu:: hovered ( QAction * action )

此信号被发射当突显菜单动作时; action 是导致信号被发射的动作。

这经常被用于更新状态信息。

另请参阅 triggered () 和 QAction::hovered ().

[protected] void QMenu:: initStyleOption ( QStyleOptionMenuItem * option , const QAction * action ) const

初始化 option with the values from this menu and information from action 。此方法对子类是有用的,当需要 QStyleOptionMenuItem ,但不希望自己填充所有信息。

另请参阅 QStyleOption::initFrom () 和 QMenuBar::initStyleOption ().

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

此方便函数插入 menu 先于动作 before 并返回菜单 menuAction ().

另请参阅 QWidget::insertAction () 和 addMenu ().

QAction *QMenu:: insertSection ( QAction * before , const QString & text )

此方便函数创建新标题动作,即:动作采用 QAction::isSeparator () 返回 true,但还有 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 拥有所有权对于返回的 QAction .

该函数在 Qt 5.1 引入。

另请参阅 QWidget::insertAction () 和 addSection ().

QAction *QMenu:: insertSection ( QAction * before , const QIcon & icon , const QString & text )

此方便函数创建新标题动作,即:动作采用 QAction::isSeparator () 返回 true,但还有 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 拥有所有权对于返回的 QAction .

该函数在 Qt 5.1 引入。

另请参阅 QWidget::insertAction () 和 addSection ().

QAction *QMenu:: insertSeparator ( QAction * before )

此方便函数创建新分隔符动作,即:动作采用 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 拥有所有权对于返回的 QAction .

另请参阅 QWidget::insertAction () 和 addSeparator ().

bool QMenu:: isEmpty () const

返回 true if there are no visible actions inserted into the menu, false otherwise.

该函数在 Qt 4.2 引入。

另请参阅 QWidget::actions ().

bool QMenu:: isTearOffMenuVisible () const

当菜单被撕离时,第 2 展示菜单会在新窗口中显示菜单内容。当菜单处于此模式下且菜单可见时,返回 true ;否则 false。

另请参阅 showTearOffMenu (), hideTearOffMenu (),和 isTearOffEnabled ().

[virtual protected] void QMenu:: keyPressEvent ( QKeyEvent * e )

重实现自 QWidget::keyPressEvent ().

[virtual protected] void QMenu:: leaveEvent ( QEvent * )

重实现自 QWidget::leaveEvent ().

返回与此菜单关联的动作。

[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 ().

显示菜单以便动作 atAction 将在指定 global 位置 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 () 和 exec ().

void QMenu:: setActiveAction ( QAction * act )

把目前突显动作设为 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.

该函数在 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 )

此函数将强制展示撕离菜单,使之出现在用户桌面指定 global 位置 pos .

该函数在 Qt 5.7 引入。

另请参阅 hideTearOffMenu (), isTearOffMenuVisible (),和 isTearOffEnabled ().

void QMenu:: showTearOffMenu ()

这是重载函数。

此函数将强制展示撕离菜单,使之出现在用户桌面鼠标光标下。

该函数在 Qt 5.7 引入。

另请参阅 hideTearOffMenu (), isTearOffMenuVisible (),和 isTearOffEnabled ().

[virtual] QSize QMenu:: sizeHint () const

重实现自 QWidget::sizeHint ().

[virtual protected] void QMenu:: timerEvent ( QTimerEvent * e )

重实现自 QObject::timerEvent ().

NSMenu *QMenu:: toNSMenu ()

返回此菜单的本机 NSMenu。只可用于 macOS。

注意: 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.

该函数在 Qt 5.2 引入。

[signal] void QMenu:: triggered ( QAction * action )

此信号被发射当触发此菜单中的动作时。

action 是导致信号被发射的动作。

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".

注意: 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 () 和 QAction::triggered ().

[virtual protected] void QMenu:: wheelEvent ( QWheelEvent * e )

重实现自 QWidget::wheelEvent ().