Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] StringList as model for GridView
Qt 6.11 is out! See what's new in the release blog

[solved] StringList as model for GridView

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ragesoft
    wrote on last edited by
    #1

    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 ;)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      athamala
      wrote on last edited by
      #2

      [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?
      [/quote]

      Use "modelData"

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

      http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodels.html

      "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."

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ragesoft
        wrote on last edited by
        #3

        -.-

        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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved