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.
This is a menu component 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.
// Create a menu with different menu items. Menu { id: myMenu // visualParent is needed to specify the grayed out area. visualParent: pageStack MenuLayout { MenuItem {text: "Red"; onClicked: { colorRect.color = "darkred" } } MenuItem {text: "Green"; onClicked: { colorRect.color = "darkgreen" }} MenuItem {text: "Blue"; onClicked: { colorRect.color = "darkblue" }} } }
The visual parent property can be 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.
Usually the menu is opened by clicking a ToolIcon. In order to close the menu on a subsequent click the following code is required:
// Toggle menu when clicking the ToolIcon twice. ToolIcon { iconId: theme.inverted ? "icon-m-toolbar-view-menu-white" : "icon-m-toolbar-view-menu"; onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close() }
Also note that you need to take care of closing the menu automatically in some situations:
// Closes the menu when changing the page in the page stack. ToolIcon { iconId: theme.inverted ? "icon-m-toolbar-back-white" : "icon-m-toolbar-back"; onClicked: { myMenu.close(); pageStack.pop(); } }
The Menu shares most of its API with the ContextMenu component.
default property alias content: contentField.children // Common API inherited from Popup: function open() function close() property QDeclarativeItem* visualParent property int status property alias title: titleBar.children // platformStyle API property Style platformStyle property Style style // Deprecated
See also MenuItem.
content : Item |
The content to be placed inside the menu.
status : int |
Returns the current status of the menu during its life cycle. Possible values are: DialogStatus.Opening, DialogStatus.Opened, DialogStatus.Closing and DialogStatus.Closed.
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.
The visual parent is an optional property which takes an Item as a type. The Item provided indicates the area on the screen that is supposed to get grayed out and become inaccessible. By default that area is the whole screen (except for the statusbar)
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.
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.
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.