Qt Reference Documentation

QML Menu Element

Provides of a list of options that the user can choose from. More...

This element was introduced in Qt Quick Components 1.0.

Properties

Methods

Detailed Description

A Menu is hidden by default and opens in response to a user action. When the user selects an option in the menu, it triggers a command.

Creating a Menu

The code snippet below shows how to create a Menu.

 // define the menu
 Menu {
     id: mainMenu
     // define the items in the menu and corresponding actions
     content: MenuLayout {
         MenuItem {
             text: "Red"
             onClicked: rect.color = "Red"
         }
             ...
     }
 }

Integrating Menu with a Toolbar

The code snippet below shows how the user can launch the menu by pressing the ToolBar's menu button.

 ToolBar {
     id: toolbar
     anchors.bottom: parent.bottom
     tools: ToolBarLayout {
         ToolButton {
             iconSource: "toolbar-back"
         }
         // add the standard menu button to the toolbar
         ToolButton {
             iconSource: "toolbar-menu"
             onClicked: mainMenu.open()
         }
     }
 }

A menu opened from a tool bar

Using Submenus

A Menu can contain submenus that are normally implemented with ContextMenu objects. The code snippet below shows how to define a ContextMenu.

 ContextMenu {
     id: cmykMenu
     MenuLayout {
         MenuItem {
             text: "Cyan"
             onClicked: rect.color = "Cyan"
         }
             ...
     }
 }

You can integrate a submenu to a menu by setting its MenuItem.platformSubItemIndicator property to true. The following code snippet shows how a submenu is integrated to the menu item.

 MenuItem {
     text: "CMYK menu"
     platformSubItemIndicator: true
     onClicked: cmykMenu.open()
 }

Property Documentation

defaultcontent : list<Item>

Provides access to the menu items in the menu. It is recommended to use a single MenuLayout object as the menu content. Usage of other objects may result in unexpected behaviour.


platformInverted : bool

Symbian:

If platformInverted is true, the component is visualized with the inverted style. For more information, see Using Inverted Style with Symbian Components. By default platformInverted is false.

This property group was introduced in Qt Quick Components 1.1.


status : int

Indicates the status of a menu. The possible values are as follows:

  • DialogStatus.Opening - the menu is opening
  • DialogStatus.Open - the menu is open and visible to the user
  • DialogStatus.Closing - the menu is closing
  • DialogStatus.Closed - the menu is closed and not visible to the user

visualParent : Item

This property is not used in Symbian. The menu always uses predefined position and fading policy.


Method Documentation

Menu::close ()

Hides the menu from the user.

Normally a menu is closed when the user selects an item from the menu. Menu is also closed when the user clicks outside the menu.


Menu::open ()

Shows the menu to the user. See the code snippet above for an example how to bind a signal to this method.