MenuItemGroup QML Type | Qt Labs Platform | Qt 6.11.1
Description: A group for managing native menu items.

- Qt 6.11
- Qt Labs Platform
- QML Types
- MenuItemGroup
- Qt 6.11.1 Reference Documentation

# MenuItemGroup QML Type

A group for managing native menu items. More...

Import Statement: | `import Qt.labs.platform`
Inherits: | QtObject

- List of all members, including inherited members

## Properties

- checkedItem : MenuItem
- enabled : bool
- exclusive : bool
- items : list<MenuItem>
- visible : bool

## Signals

- hovered(MenuItem item)
- triggered(MenuItem item)

## Methods

- void addItem(MenuItem item)
- void clear()
- void removeItem(MenuItem item)

## Detailed Description

The MenuItemGroup groups native menu items together.

MenuItemGroup is exclusive by default. In an exclusive menu item group, only one item can be checked at any time; checking another item automatically unchecks the previously checked one. MenuItemGroup can be configured as non-exclusive, which is particularly useful for showing, hiding, enabling and disabling items together as a group.

The most straight-forward way to use MenuItemGroup is to assign a list of items.

     Menu {
         id: verticalMenu
         title: qsTr("Vertical")

         MenuItemGroup {
             id: verticalGroup
             items: verticalMenu.items
         }

         MenuItem { text: qsTr("Top"); checkable: true }
         MenuItem { text: qsTr("Center"); checked: true }
         MenuItem { text: qsTr("Bottom"); checkable: true }
     }

The same menu may sometimes contain items that should not be included in the same exclusive group. Such cases are best handled using the group property.

     Menu {
         id: horizontalMenu
         title: qsTr("Horizontal")

         MenuItemGroup {
             id: horizontalGroup
         }

         MenuItem {
             checked: true
             text: qsTr("Left")
             group: horizontalGroup
         }
         MenuItem {
             checkable: true
             text: qsTr("Center")
             group: horizontalGroup
         }
         MenuItem {
             text: qsTr("Right")
             checkable: true
             group: horizontalGroup
         }

         MenuItem { separator: true }
         MenuItem { text: qsTr("Justify"); checkable: true }
         MenuItem { text: qsTr("Absolute"); checkable: true }
     }

More advanced use cases can be handled using the addItem() and removeItem() methods.

Note: Types in Qt.labs modules are not guaranteed to remain compatible in future versions.

See also MenuItem.

## Property Documentation

### checkedItem : MenuItem

This property holds the currently checked item in the group, or `null` if no item is checked.

### enabled : bool

This property holds whether the group is enabled. The default value is `true`.

The enabled state of the group affects the enabled state of each item in the group, except that explicitly disabled items are not enabled even if the group is enabled.

### exclusive : bool

This property holds whether the group is exclusive. The default value is `true`.

In an exclusive menu item group, only one item can be checked at any time; checking another item automatically unchecks the previously checked one.

### items : list<MenuItem>

This property holds the list of items in the group.

### visible : bool

This property holds whether the group is visible. The default value is `true`.

The visibility of the group affects the visibility of each item in the group, except that explicitly hidden items are not visible even if the group is visible.

## Signal Documentation

### hovered(MenuItem item)

This signal is emitted when an item in the group is hovered by the user.

Note: The corresponding handler is `onHovered`.

See also MenuItem::hovered().

### triggered(MenuItem item)

This signal is emitted when an item in the group is triggered by the user.

Note: The corresponding handler is `onTriggered`.

See also MenuItem::triggered().

## Method Documentation

### void addItem(MenuItem item)

Adds an item to the group.

### void clear()

Removes all items from the group.

### void removeItem(MenuItem item)

Removes an item from the group.