Skip to content
Advertisement

Working with delegate model and delegate model group dynamically QML?

I have been using a DelegateModel and DelegateModelGroup to only show certain items of a List Model in my delegate. The process is essentially the same as the process described in the first answer to this question. The code for the DelegateModel is below.

JavaScript

I am using this so that only 3 random elements from a ListModel are shown in a delegate at once. I then use a function to update these once a timer from c++ times out and emits a signal so a new 3 elements are used. Here is the code for the updating function and he connection with c++.

JavaScript

At the start, it automatically calls the function with Component.onCompleted as well. My problem is that I cannot figure out how to remove everything from the group before I switch them out. I thought that the items.remove line would do it, but even though the items.count becomes zero, the items still appear in the delegate and the items.insert just adds to to the bottom (so 6 delegates are visible).

Does anyone know a way I could do this, if I have a simple syntax or I should be using an entirely different approach?

Advertisement

Answer

I don’t think removing elements from items group makes any difference, what you need to do is make the filter group as includeByDefault , then remove items from that group , namely todaysMissions ;

From documentation

items : DelegateModelGroup

This property holds default group to which all new items are added.

filterOnGroup : string

This property holds name of the group that is used to filter the delegate model.

Only items that belong to this group are visible to a view.

By default this is the items group.

note that items are automatically added to the items group , and that only items in the filtergroup are visible

Here is an example for filtering GridView:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement