Menu QML Type | Qt Labs Controls 5.6

Qt 5.6 | Qt Labs Controls | QML Types | Menu QML Type

Qt 5.6.3 Reference Documentation

# Menu QML Type

A menu control. More...

Import Statement: | import Qt.labs.controls 1.0
Inherits: | Popup

- List of all members, including inherited members

## Properties

- contentData : list<Object>
- contentModel : model
- title : string

## Methods

- void addItem(Item item)
- void insertItem(int index, Item item)
- Item itemAt(int index)
- void moveItem(int from, int to)
- void removeItem(int index)

## Detailed Description

Menu has two main use cases:

- Context menus; for example, a menu that is shown after right clicking
- Popup menus; for example, a menu that is shown after clicking a button

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

          Menu {
              id: menu
              y: fileButton.height

              MenuItem {
                  text: "New..."
              }
              MenuItem {
                  text: "Open..."
              }
              MenuItem {
                  text: "Save"
              }
          }
      }

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

See also Customizing Menu and Menu Controls.

## Property Documentation

[default] contentData : list<Object>

This property holds the list of content data.

See also Item::data.

[read-only] contentModel : model

This property holds the model used to display menu items.

By default, the model is an ObjectModel, in order to allow declaring menu items as children of the menu.

title : string

Title for the menu as a submenu or in a menubar.

Its value defaults to an empty string.

## Method Documentation

void addItem(Item item)

Adds item to the end of the list of items.

void insertItem(int index, Item item)

Inserts item at index.

Item itemAt(int index)

Returns the item at index, or `null` if it does not exist.

void moveItem(int from, int to)

Moves an item from one index to another.

void removeItem(int index)

Removes an item at index.

Note: The ownership of the item is transferred to the caller.