Qt Reference Documentation

QML ContextMenu Element

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

This element was introduced in Qt Quick Components 1.0.



Detailed Description

There are two typical use cases for the ContextMenu component. You can use it as a context sensitive menu that opens, for example, on an object's long press signal, or you can use it to show a submenu.

Creating a ContextMenu

The following code snippet shows how to create a ContextMenu.

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

The screenshot below illustrates the result of the code snippet.

See the Menu documentation for an example on how to use a ContextMenu as a submenu.

Property Documentation

defaultcontent : list<Item>

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

platformInverted : bool


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 context 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 context menu always uses the predefined position and fading policy.

Method Documentation

ContextMenu::close ()

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

ContextMenu::open ()

Shows the context menu to the user.