[Interest] Implementing tag cloud with QML

Nuno Santos nunosantos at imaginando.pt
Mon Sep 28 11:19:18 CEST 2015


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,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150928/64c42a2b/attachment.html>

More information about the Interest mailing list