diff options
| author | Mitch Curtis <mitch.curtis@qt.io> | 2022-08-03 11:21:59 +0800 |
|---|---|---|
| committer | Mitch Curtis <mitch.curtis@qt.io> | 2022-10-21 09:13:36 +0800 |
| commit | a0f662640b885f3562bc3a33fcbbe5bdffc27410 (patch) | |
| tree | a7dc4a2d480b8219e771134335742274436b4cb6 /src/labs/platform/qquicklabsplatformmenu.cpp | |
| parent | 648df1b98beb9ec04ba87a297628df4209a68959 (diff) | |
Doc: unify "Dynamically Generating Menu Items" across modules
Both Qt Quick Controls and Qt Labs Platform can use the exact same
snippet for this, so use the same approach in both modules.
I would try to reuse the code (and documentation), but I'm not sure if
the linking to the types contained within would work, nor if there
would be conflicts, so to err on the side of caution, give each module
its own copies.
Task-number: QTBUG-64554
Change-Id: Id1cac733ad3eda12074234f882eeae289caa438a
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/labs/platform/qquicklabsplatformmenu.cpp')
| -rw-r--r-- | src/labs/platform/qquicklabsplatformmenu.cpp | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/src/labs/platform/qquicklabsplatformmenu.cpp b/src/labs/platform/qquicklabsplatformmenu.cpp index cd23813d63..60a7843001 100644 --- a/src/labs/platform/qquicklabsplatformmenu.cpp +++ b/src/labs/platform/qquicklabsplatformmenu.cpp @@ -91,43 +91,13 @@ QT_BEGIN_NAMESPACE } \endqml - \section2 Dynamically Generating Menu Items + \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: + You can dynamically generate menu items with \l Instantiator. The following + code shows how you can implement a "Recent Files" submenu, where the items + come from a list of files stored in settings: - \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 + \snippet qtlabsplatform-menu-instantiator.qml menu \section2 Availability |
