[SailfishDevel] Dynamically populate a ContextMenu
Tigre-Bleu
devel at tigre-bleu.net
Tue Nov 26 00:03:36 UTC 2013
Repeater is a nice & clean solution.
I'll go with that.
Thanks
----- Mail original -----
De: "Martin Kampas" <martin.kampas at tieto.com>
À: devel at lists.sailfishos.org, "Tigre-Bleu" <devel at tigre-bleu.net>
Cc: "christopher lamb" <christopher.lamb at thurweb.ch>, "Andrey Kozhevnikov" <coderusinbox at gmail.com>
Envoyé: Lundi 25 Novembre 2013 09:25:19
Objet: Re: [SailfishDevel] Dynamically populate a ContextMenu
Hi,
simply assign id to one of the static items, e.g. firstStatic, and then use firstStatic.parent instead of menu._contentColumn as parent for the dynamic items -- this way you do not rely on implementation details:
menu: ContextMenu {
id: menu
MenuItem { id: firstStatic; text: "Static 1" }
MenuItem { text: "Static 2" }
}
Component.onCompleted: {
console.debug("Populating menu")
for (var i=0; i< 4 ; i++){
var newMenuItem = menuItemComp.createObject(firstStatic.parent,
{"text" : "Dynamic" + i})
}
}
Event better consider using Repeater and provide the list of dynamic items as item model[1] (assiging a number as a model gives exactly the same result as in your original example):
ApplicationWindow {
initialPage: Page {
ComboBox {
width: parent.width
label: "Menu"
menu: ContextMenu {
id: menu
MenuItem { text: "Static 1" }
MenuItem { text: "Static 2" }
Repeater {
model: 4
MenuItem { text: "Dynamic " + index }
}
}
}
}
}
BR,
Martin
[1] https://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-repeater.html#model-prop
On Saturday, November 23, 2013 04:06:40 PM christopher.lamb at thurweb.ch wrote:
> Hi Andrey
>
> Zitat von "Andrey Kozhevnikov" <coderusinbox at gmail.com>:
> > you may need to make childs of menu._contentColumn, not just menu.
>
> I thought that the underscore stuff are private internal properties /
> functions that we mere mortals should not be using ....8-) (Not that
> that would necessarily stop me).
>
> Chris
>
>
> _______________________________________________
> SailfishOS.org Devel mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20131126/4054abc8/attachment.html>
More information about the Devel
mailing list