aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-03-06 12:15:11 +0100
committerMitch Curtis <mitch.curtis@qt.io>2018-03-06 13:01:49 +0000
commite4901286c801162d6b9b94b10d23dafca73c5068 (patch)
tree1763799dec6f3c987f4a409d4c9ce8e22ef8513c /src
parentb4db69eee6dc2f381b24aa24586171dbaf8d116e (diff)
Doc: add an example of submenus and dynamically generated menu items
Task-number: QTBUG-66874 Change-Id: I1e34039e4fa0344b1efdcb2977586d97ada6b31e Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/platform/qquickplatformmenu.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/imports/platform/qquickplatformmenu.cpp b/src/imports/platform/qquickplatformmenu.cpp
index ec5c4804..6168938c 100644
--- a/src/imports/platform/qquickplatformmenu.cpp
+++ b/src/imports/platform/qquickplatformmenu.cpp
@@ -100,6 +100,68 @@ QT_BEGIN_NAMESPACE
}
\endcode
+ \section2 Submenus
+
+ To create submenus, declare a Menu as a child of another Menu:
+
+ \qml
+ Menu {
+ title: qsTr("Edit")
+
+ Menu {
+ title: qsTr("Advanced")
+
+ MenuItem {
+ text: qsTr("Auto-indent Selection")
+ onTriggered: autoIndentSelection()
+ }
+
+ MenuItem {
+ text: qsTr("Rewrap Paragraph")
+ onTriggered: rewrapParagraph()
+ }
+ }
+ }
+ \endqml
+
+ \section2 Dynamically Generating Menu Items
+
+ It is possible to dynamically generate menu items. One of the easiest ways
+ to do so is with \l Instantiator. For example, to implement a
+ "Recent Files" submenu, where the items are based on a list of files stored
+ in settings, the following code could be used:
+
+ \qml
+ Menu {
+ title: qsTr("File")
+
+ Menu {
+ id: recentFilesSubMenu
+ title: qsTr("Recent Files")
+ enabled: recentFilesInstantiator.count > 0
+
+ Instantiator {
+ id: recentFilesInstantiator
+ model: settings.recentFiles
+ delegate: MenuItem {
+ text: settings.displayableFilePath(modelData)
+ onTriggered: loadFile(modelData)
+ }
+
+ onObjectAdded: recentFilesSubMenu.insertItem(index, object)
+ onObjectRemoved: recentFilesSubMenu.removeItem(object)
+ }
+
+ MenuSeparator {}
+
+ MenuItem {
+ text: qsTr("Clear Recent Files")
+ onTriggered: settings.clearRecentFiles()
+ }
+ }
+ }
+ \endqml
+
\section2 Availability
A native platform menu is currently available on the following platforms: