[Interest] Implementing tag cloud with QML

Ben Lau xbenlau at gmail.com
Mon Sep 28 11:54:51 CEST 2015


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 <nunosantos at 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 at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150928/72e2b531/attachment.html>


More information about the Interest mailing list