Good Morning all,
Disclamer: I know a very close subject exists already, but from what I understood the “repeater” only “repeats” identical objects and can’t create different ones.
I’ve been trying for the past days to update my app so it becomes more maintainable in the future.
To do so I’d like to create dynamic MenuItems in a ContextMenu from an array. I.E: EN, English, ES, Spanish, GE, German, etc… .
I thought about using the “Instantiator”, but there are barely existing code examples. I tried following these examples from the Qt forum 1, 2, 3, 4, 5, but they all use the Qt Quick Controls which is only available starting at Qt 5.7…
import QtQuick 2.6
import Sailfish.Silica 1.0
import QtQml 2.2
Page {
SilicaFlickable {
anchors.fill: parent
bottomMargin: Theme.paddingLarge
Column {
width: parent.width
PageHeader {
title: "Combo boxes"
}
ComboBox {
label: "Language List"
menu : ContextMenu {
id: contextMenu
Instantiator {
active : true
model: 10
delegate: QtObject {
property Item child: MenuItem {
text: model.index
onClicked: console.log(index)
}
}
}
}
}
}
}
Before jumping to the use of an array I’m trying to do this with a model fixed size. And the current output is an “empty” ContextMenu (if i click on it, nothing is displayed, not even errors in the console):
If someone has any input regarding this I would be VERY thankful ! My first goal would be to have 10 MenuItems appearing when I click on the “Language List”.