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. Different delegates at the repeater
Forum Update on Monday, May 27th 2025

Different delegates at the repeater

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.1k Views
  • 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.
  • M Offline
    M Offline
    maxim.prishchepa
    wrote on 21 Dec 2014, 12:34 last edited by
    #1

    Hello everyone, could you help with little issue:
    I'd like to make a different delegates at the repeater,
    for example i have model like this:
    @ListModel {
    ListElement {
    name: "1"
    itemDelegate: "1.qml"
    }
    ListElement {
    name: "2"
    itemDelegate: "2.qml"
    }
    }@

    i try to use something like:
    @Repeater {
    id: repeater
    model: tabModel
    delegate: Qt.createComponent(Qt.resolvedUrl(itemDelegate))
    }@

    but have warning:
    "ReferenceError: itemDelegate is not defined"

    is it possible to make a different delegates at the Repeater component?

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 21 Dec 2014, 13:37 last edited by
      #2

      Hi,

      AFAIK the roles can be accessed only inside the component assigned to delegate. You can do following instead,
      @
      delegate: Item {
      id: item
      Component.onCompleted: {
      var component = Qt.createComponent(Qt.resolvedUrl(itemDelegate))
      var obj = component.createObject(item);
      obj.y = index*40
      }
      }
      @

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxim.prishchepa
        wrote on 21 Dec 2014, 15:13 last edited by
        #3

        tnx 4 answer!
        how i understand i should manualy calculate possition of new item?

        is it possible to use some anchors?
        currently i make this:
        @ delegate: Item {
        id: item
        width: children.width
        height: children.height
        Component.onCompleted: {
        var component = Qt.createComponent(Qt.resolvedUrl(itemDelegate))
        var obj = component.createObject(item);
        }
        }@
        but i saw only last item, as i understand i should manualy shift items in the repeater, but IMO this is some spike...

        is some way to correct solve this issue?

        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxim.prishchepa
          wrote on 21 Dec 2014, 15:19 last edited by
          #4

          btw, don't know is it importent or not:
          i use
          @Flickable {
          anchors {
          top: header.bottom
          left: parent.left
          right: parent.right
          }
          height: 100
          contentWidth: row.width
          Row {
          id: row
          spacing: 1

                  Repeater {
                      id: repeater
                      model: myModel
                      delegate: Item {
                          id: factoryItem
                          width: children.width
                          height: children.height
                          Component.onCompleted: {
                              var component = Qt.createComponent(Qt.resolvedUrl(null != itemDelegate ? itemDelegate : "DefaultDelegate.qml"))
                              var obj = component.createObject(factoryItem);
                          }
                      }
                  }
              }
          

          }@

          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

          1 Reply Last reply
          0
          • P Offline
            P Offline
            p3c0
            Moderators
            wrote on 22 Dec 2014, 05:22 last edited by
            #5

            bq. how i understand i should manualy calculate possition of new item?

            createObject returns the object that is created. It can be used to assign values to its properties.
            @
            var obj = component.createObject(item);
            obj.y = index*40
            @

            Or (as you have already did) putting it in Row or Column should also work.

            157

            1 Reply Last reply
            0

            4/5

            21 Dec 2014, 15:19

            • Login

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