MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

QML ContextMenu Element

A Context Menu component for selecting a menu item from a list of menu items. More...

Inherits Popup

This element was introduced in qt-components 4.7.

Properties

Methods

Detailed Description

A Context Menu componentis for selecting a menu item from a list of menu items. Each menu item displays some text and can be associated with a custom action that is performed on the clicked signal.

The menu items are arranged in a layout via the MenuLayout element. Note that this layout and its implementation can vary depending on the UI guidelines of the platform.

 PageStackWindow {
   id: rootWindow
   initialPage: Page {

     // long press rectangle to open the ContextMenu
     Rectangle {
         id: contextColorRect
         anchors.centerIn: parent
         width: 100; height: 100
         color: "black"
         MouseArea {
             id: longPressArea
             anchors.fill: parent
             onPressAndHold: myContextMenu.open()
         }
     }

     // Create a menu with different menu items.
     ContextMenu {
         id: myContextMenu
         MenuLayout {
             MenuItem {text: "Red"; onClicked: { contextColorRect.color = "darkred" } }
             MenuItem {text: "Green"; onClicked: { contextColorRect.color = "darkgreen" }}
             MenuItem {text: "Blue"; onClicked: { contextColorRect.color = "darkblue" }}
             MenuItem {text: "Black is an extremely beautiful and stylish color"; onClicked: { contextColorRect.color = "black" }}
         }
       }
    }
  }

The visual parent property is used to specify which area of the screen is grayed out while the menu is opened. If no visual parent is set then it is determined automatically and falls back to the root item.

The ContextMenu shares most of its API with the ContextMenu component.

Common API

     default property alias content: contentField.children

     // Common API inherited from Popup:
     function open()
     function close()

     property QDeclarativeItem* visualParent
     property int status

     property list<Item> title: titleBar.children

     // platformStyle API
     property Style platformStyle
     property string platformTitleText
     property Item platformIcon

     property Style style // Deprecated

See also MenuItem.

Property Documentation

content : Item

The content to be placed inside the menu.


platformStyle : Style

Property default is MenuStyle{}.

Property for styling the component.


status : int

Returns the current status of the menu during its life cycle. Possible values: DialogStatus.Opening, DialogStatus.Opened, DialogStatus.Closing and DialogStatus.Closed.


title : list<Item>

The items that provide the title information.


visualParent : QDeclarativeItem*

Property default is the root element.

The visual parent marks the element that occupies the area which is supposed to be grayed out while the menu is open.


Method Documentation

ContextMenu::close ()

Closes the menu and changes the status to DialogStatus.Closing for the animation phase. Once the menu is opened the status is changed to DialogStatus.Closed.


ContextMenu::open ()

Opens the menu and changes the status to DialogStatus.Opening for the animation phase. Once the menu is opened the status is changed to DialogStatus.Open.