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
QtWS25 Last Chance

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 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
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on 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 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 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
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on 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

            • Login

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