Commit 92d6272e authored by Yuya Nishihara's avatar Yuya Nishihara

Add example of dynamic menu registration

parent af5e2c6b
......@@ -2,6 +2,8 @@ import QtQuick 2.12
import QtQuick.Controls 2.12
ApplicationWindow {
id: window
visible: true
width: 640
height: 480
......@@ -15,4 +17,48 @@ ApplicationWindow {
Action { text: qsTr("&Quit") }
}
}
// Instantiated statically, but registered dynamically
Menu {
id: debugMenu
visible: false
title: qsTr("&Debug")
Action { text: qsTr("Static action") }
}
// Instantiated dynamically
Component {
id: dynamicMenuComponent
Menu {
visible: false
title: qsTr("D&aynamic")
Action { text: qsTr("Static action") }
}
}
Action {
id: dynamicallyRegisteredAction
text: qsTr("Dynamically registered action")
}
Component.onCompleted: {
window.menuBar.addMenu(debugMenu);
}
Timer {
running: true
interval: 2000
onTriggered: {
let menu = dynamicMenuComponent.createObject(window);
window.menuBar.addMenu(menu);
}
}
Timer {
running: true
interval: 4000
onTriggered: {
debugMenu.addAction(dynamicallyRegisteredAction);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment