May be it is not a perfect solution, I usually fix this kind of problem by adding a timestamp of last update ( (new Date()).getTime() ) . Then force those items to refresh on value changes.
On 28 September 2015 at 18:36, Nuno Santos <nunosan...@imaginando.pt> wrote: > Ben, > > Item is of class Item > itemList model is of class QList<Item*> > > Item has the property tags which is of type QStringList > Each item has ItemManager, the holder of itemList model, as parent > > On toggleTag I’m doing this: > > void DRCPatch::toggleTag(QString tag) > { > if (_tags.contains(tag)) > _tags.removeOne(tag); > else > _tags.append(tag); > > emit _manager->tagsChanged(); > } > > And in fact, the model is returned. I have confirmed that the model > property has been called. However, ListView doesn’t update or re-layout if > the items are exactly the same. > > If here I do _tags.append(“something”) it will update and behave as > expected. > > QStringList ItemManager::tags() > { > return _tags; > } > > Any ideas on how to work around this? > > Regards, > > Nuno > > On 28 Sep 2015, at 10:54, Ben Lau <xben...@gmail.com> wrote: > > How do you use the toggleTag? And what is the data type of element in > itemList.model? > > > > On 28 September 2015 at 17:19, Nuno Santos <nunosan...@imaginando.pt> > wrote: > >> Hi, >> >> I was trying to implement a tag cloud with a ListView but I'm facing some >> unexpected problems. My idea was the following: >> >> A ListView would have a model of tags, based on a QStringList. Other list >> view would have items (custom model), each item would have associated tags. >> I want to concentrate the tags in a single list in the UI. So, when you >> select an item, it will display all the tags, and the ones which are >> present in that item would get highlighted. >> >> Every time I click a tag, it will toggle that tag for the respective >> item. The problem is that for some reason, ListView seems to cache the data >> model and thus it doesn’t get redrawn. Because the tags are the exactly the >> same. What changed was item tags list. >> >> Is there anyway to bypass the model cache or force the ListView to >> redraw? I can’t find any suitable method on ListView documentation. >> >> I’m not finding an obvious solution for this problem and I believe that >> is a simple solution for it. Any ideas? >> >> ListView { >> id: tagsList >> model: tags >> delegate: Rectangle { >> color: "transparent" >> border.color: "white" >> border.width: 1 >> >> Text { >> id: tagLabel >> color: "gray" >> text: "#"+modelData >> Component.onCompleted: { >> var tags = itemList.model[itemList.currentIndex].tags; >> >> for (var i=0;i<tags.length;i++) >> { >> if (tags[i]==modelData) >> color = "white" >> } >> } >> } >> >> MouseArea { >> anchors.fill: parent >> onClicked: >> itemList.model[itemList.currentIndex].toggleTag(modelData) >> } >> } >> } >> >> Thanks in advance, >> >> Regards, >> >> Nuno >> >> _______________________________________________ >> Interest mailing list >> Interest@qt-project.org >> http://lists.qt-project.org/mailman/listinfo/interest >> >> > >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest