|  | Home · Overviews · Examples |

# QMenu Class Reference
[com.trolltech.qt.gui module]

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

Inherits `QWidget`.

## Detailed Description

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

A menu widget is a selection menu. It can be either a pull-down menu in a menu bar or a standalone context menu. Pull-down menus are shown by the menu bar when the user clicks on the respective item or presses the specified shortcut key. Use QMenuBar::addMenu() to insert a menu into a menu bar. Context menus are usually invoked by some special keyboard key or by right-clicking. They can be executed either asynchronously with `popup` or synchronously with `exec`. Menus can also be invoked in response to button presses; these are just like context menus except for how they are invoked.

A menu shown in Plastique widget style, Windows XP widget style, and Macintosh widget style.

A menu consists of a list of action items. Actions are added with `addAction`. 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".

There are three kinds of action items: separators, actions that show a submenu, and actions that perform an action. Separators are inserted with `addSeparator`. For submenus use `addMenu`. 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, activated() and highlighted(), which signal the `QAction` that was triggered from the menu.

You clear a menu with `clear` and remove individual action items with `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`. When using tear-off menus, bear in mind that the concept isn't typically used on Microsoft Windows so some users may not be familiar with it. Consider using a `QToolBar` instead.

See the Menus example for an example of how to use `QMenuBar` and `QMenu` in your application.

Important inherited functions: `addAction`, `removeAction`, `clear`, `addSeparator`, and `addMenu`.

See also `QMenuBar`, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Application Example, Menus Example, and Recent Files Example.