Qt Reference Documentation

QML MenuItem Element

Provides a menu item for accessing to a particular function. More...

This element was introduced in Qt Quick Components 1.0.

Properties

Signal Handlers

Detailed Description

Menu items are normally added as child items to a MenuLayout that is associated with a menu.

See the Menu documentation for a more information on how to use menus.

Custom Menu Items

You can utilize the platformLeftMargin property for creating custom menu items. The example below shows how to create a menu item with the check mark support.

 // MenuItemWithCheck.qml

 import QtQuick 1.1
 import com.nokia.symbian 1.1

 MenuItem {
     id: root

     property bool checked: false

     platformLeftMargin: 2 * platformStyle.paddingMedium + platformStyle.graphicSizeSmall

     Image {
         id: checkIcon

         anchors {
             left: parent.left
             leftMargin: platformStyle.paddingMedium
             verticalCenter: parent.verticalCenter
         }

         visible: root.checked
         source: "check.svg"
         sourceSize.width: platformStyle.graphicSizeSmall
         sourceSize.height: platformStyle.graphicSizeSmall
     }
 }

You can now create the menu using custom menu item, in this case MenuItemWithCheck.qml.

 // define the menu
 Menu {
     id: mainMenu
     // fill the menu layout with custom menu items
     content: MenuLayout {
         MenuItemWithCheck {
             checked: true
             text: "Checked"
         }
         MenuItemWithCheck {
             checked: false
             text: "Not checked"
         }
         MenuItemWithCheck {
             text: "Not checked (default)"
         }
     }
 }

The image below shows how the custom menu looks like.

Property Documentation

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.


platformLeftMargin : real

Sets the menu item's left margin. The margin defines the space between the menu item's left edge and the text content's start position.


platformSubItemIndicator : bool

Defines whether this menu item has subitems or not. If the value is true, the menu item shows an an icon indicating to the user that the item has subitems. If the value is false, the item does not show the icon and does not have subitems. Normally subitems are shown by opening a ContextMenu that contains the additional menu items.


text : string

The text that is shown on this menu item.


Signal Handler Documentation

MenuItem::clicked ()

This signal is emitted when the user selects this menu item.