Perform an action when a repeater is done updating a component
-
Hi there,
I have a QML Menu that is filled with MenuItems through a repeater.
I would like to be able to add in that same menu, after the repeater's entries, a MenuSeparator, followed by other MenuItems, but I want those new items to always show up after the ones added by the repeater, even if the model changes at some point.My current code looks like this:
Menu { id: menu title: "Open recent" enabled: recentsList.length property var recentsModel: ListModel { id: mModel } property var modelList: recentsList onModelListChanged: { mModel.clear() for (var i = 0 ; i < modelList.length ; i++) mModel.append({"index": i, "title": modelList[i], "fileUrl": modelList[i]}) } Repeater { model: mModel MenuItem { text: model.title onTriggered: { // doSomething } } } MenuSeparator { visible: menu.enabled } MenuItem { text: "Clear Recents" onTriggered: recentsList.clear() } }
This code works, until my model changes, in which case the repeater removes the old items from the view, and appens them back, after my separator and my "Clear Recents" MenuItem.
I searched for a signal maybe, from the repeater that would tell me when he's done updating the view, but I didn't find anything like that.
Is it possible to guarantee that my elements are added After the repeater has updated the view from the model?
Thanks in advance for your kind answers!
-
Hi there,
I have a QML Menu that is filled with MenuItems through a repeater.
I would like to be able to add in that same menu, after the repeater's entries, a MenuSeparator, followed by other MenuItems, but I want those new items to always show up after the ones added by the repeater, even if the model changes at some point.My current code looks like this:
Menu { id: menu title: "Open recent" enabled: recentsList.length property var recentsModel: ListModel { id: mModel } property var modelList: recentsList onModelListChanged: { mModel.clear() for (var i = 0 ; i < modelList.length ; i++) mModel.append({"index": i, "title": modelList[i], "fileUrl": modelList[i]}) } Repeater { model: mModel MenuItem { text: model.title onTriggered: { // doSomething } } } MenuSeparator { visible: menu.enabled } MenuItem { text: "Clear Recents" onTriggered: recentsList.clear() } }
This code works, until my model changes, in which case the repeater removes the old items from the view, and appens them back, after my separator and my "Clear Recents" MenuItem.
I searched for a signal maybe, from the repeater that would tell me when he's done updating the view, but I didn't find anything like that.
Is it possible to guarantee that my elements are added After the repeater has updated the view from the model?
Thanks in advance for your kind answers!
Hi
@lagarkane said in Perform an action when a repeater is done updating a component:but I want those new items to always show up after the ones added by the repeater, even if the model changes at some point.
you can use Qt Quick Layouts to handle that
ColumnLayout{ spacing: 2 Item{ Repeater { model: mModel MenuItem { text: model.title onTriggered: { // doSomething } } } } MenuSeparator {} MenuItem {} }