MenuItem QML Type | Qt Quick Controls | Qt 6.11.1
Description: Presents an item within a Menu.

- Qt 6.11
- Qt Quick Controls
- QML Types
- MenuItem
- Qt 6.11.1 Reference Documentation

# MenuItem QML Type

Presents an item within a Menu. More...

Import Statement: | `import QtQuick.Controls`
Inherits: | AbstractButton

- List of all members, including inherited members

## Properties

- arrow : Item `(since QtQuick.Controls 2.3 (Qt 5.10))`
- highlighted : bool
- implicitTextPadding : real `(since 6.8)`
- menu : Menu `(since QtQuick.Controls 2.3 (Qt 5.10))`
- subMenu : Menu `(since QtQuick.Controls 2.3 (Qt 5.10))`
- textPadding : real `(since 6.8)`

## Signals

- void triggered()

## Detailed Description

MenuItem is a convenience type that implements the AbstractButton API, providing a familiar way to respond to menu items being triggered, for example.

MenuItem inherits its API from AbstractButton. For instance, you can set text and icon using the AbstractButton API.

     Button {
         id: fileButton
         text: "File"
         onClicked: menu.open()

         Menu {
             id: menu

             MenuItem {
                 text: "New..."
                 onTriggered: document.reset()
             }
             MenuItem {
                 text: "Open..."
                 onTriggered: openDialog.open()
             }
             MenuItem {
                 text: "Save"
                 onTriggered: saveDialog.open()
             }
         }
     }

See also Customizing Menu, Menu, and Menu Controls.

## Property Documentation

### arrow : Item `[since QtQuick.Controls 2.3 (Qt 5.10)]`

This property holds the sub-menu arrow item.

This property was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also Customizing Menu.

### highlighted : bool

This property holds whether the menu item is highlighted by the user.

A menu item can be highlighted by mouse hover or keyboard navigation.

The default value is `false`.

See also Menu::currentIndex.

### implicitTextPadding : real `[since 6.8]`

This property holds the minimum space needed from the left edge of the contentItem to the text. It's used to calculate a common textPadding among all the MenuItems inside a Menu.

This property was introduced in Qt 6.8.

See also textPadding.

### menu : Menu `[read-only, since QtQuick.Controls 2.3 (Qt 5.10)]`

This property holds the menu that contains this menu item, or `null` if the item is not in a menu.

This property was introduced in QtQuick.Controls 2.3 (Qt 5.10).

### subMenu : Menu `[read-only, since QtQuick.Controls 2.3 (Qt 5.10)]`

This property holds the sub-menu that this item presents in the parent menu, or `null` if this item is not a sub-menu item.

This property was introduced in QtQuick.Controls 2.3 (Qt 5.10).

### textPadding : real `[read-only, since 6.8]`

This property holds the maximum implicitTextPadding found among all the menu items inside the same menu.

This property can be used by the style to ensure that all MenuItems inside the same Menu end up aligned with respect to the text.

A Menu can consist of meny different MenuItems, some can be checkable, some can have an icon, and some will just contain text. And very often, a style wants to make sure that the text inside all of them ends up left-aligned (or right-aligned for mirrored items). By letting each MenuItem assign its own minimum text padding to implicitTextPadding (taking icons and checkmarks into account), but using textPadding to actually position the text, all MenuItems should end up being aligned

In order for this to work, all MenuItems should set implicitTextPadding to be the minimum space needed from the left edge of the contentItem to the text.

This property was introduced in Qt 6.8.

See also implicitTextPadding.

## Signal Documentation

### void triggered()

This signal is emitted when the menu item is triggered by the user.

Note: The corresponding handler is `onTriggered`.