Menu QML Type

A menu control that can be used as a context menu or popup menu. More...

Import Statement: import QtQuick.Controls 2.0
Since: Qt 5.7
Inherits:

Popup

Properties

Methods

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

See also Customizing Menu, Menu Controls, and Popup 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.