[solved] StringList as model for GridView

  • Hi,

    this is my first post here and i'm realy new to Qt and Qt Quick.

    So i saw the amazing flickr-demo and started to change a bit on the code.

    i'm now at a position, where i got a string (the tags of an image) and have to split it up into the single tags.
    this tags i want to display in a grid view.
    So here is my attampt of doing so:

    @GridView {
    id: tagGrid
    anchors {
    left: parent.left; leftMargin: 10
    right: parent.right; rightMargin: 10
    top: parent.top; topMargin: 5
    bottom: parent.bottom; bottomMargin: 5
    cellWidth: (parent.width-20)/4
    cellHeight: 15
    width: parent.width - 20; height: parent.height -10
    model: container.photoTags.split(" ")
    delegate: tagDelegate
    clip: true

    as u can see, i us the split-function to provide the data to the view.
    The delegate should show a simple text-item for each of the contained strings. this works!
    but i dont see the String itself and i dont know, how to refer to it!

    here is my delegate:
    @Component {
    id: tagDelegate

    Text { color: "white"; elide: Text.ElideRight; text: "#"+ s; width: (tagContainer.width - 20) / 4 }


    the problme is the "text"-property. i wrote "s" for example. i know, this i wrong, but how to get the current stringlist-item?

    thx for your help :D

    if u got any other idee, how to get a simple grid view out of a splitted string, show it to me ;)

  • [quote author="ragesoft" date="1297331065"]
    The problme is the "text"-property. i wrote "s" for example. i know, this i wrong, but how to get the current stringlist-item?

    Use "modelData"

    @Text { color: "white"; elide: Text.ElideRight; text: "#"+ modelData; width: (tagContainer.width - 20) / 4 }@


    "Models that do not have named roles (such as the QStringList model shown below) will have the data provided via the modelData role. The modelData role is also provided for models that have only one role. In this case the modelData role contains the same data as the named role."

  • -.-

    boar, i've read this part about 10 times!
    but i didnt recognize that "modelData" is the role-name -.-

    sorry for this first and stupid question, but dont worry, there will be more :D

  • ragesoft, don't forget to mark thread as [solved]

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.