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. using Component in multiple Repeaters - how to identify Repeater from Component?
Forum Updated to NodeBB v4.3 + New Features

using Component in multiple Repeaters - how to identify Repeater from Component?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 303 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    I hope the title makes sense. Here's a snippet of what I'm trying to do:

    Column {
        Repeater {
            id: repeaterA
            model: c_plus_plus_function_that_returns_QList(ArgumentA)
            delegate: myComponent 
        }
        Repeater {
            id: repeaterB
            model: c_plus_plus_function_that_returns_QList(ArgumentB)
            delegate: myComponent 
        }
        Repeater {
            id: repeaterC
            model: c_plus_plus_function_that_returns_QList(ArgumentC)
            delegate: myComponent 
        }
    }
    
    Component {
        id: myComponent
            Rectangle {
                visible: index < repeater.count // what to use for repeater here?
    

    How can I uniquely identify the repeater from within the component? All I really need is the model size.

    Thanks...

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by dheerendra
      #2

      Try doing something like this.

      import QtQuick
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          Component{
              id : comp
              Rectangle {
                  property var rep
                  width: 150;height: 50;color:"blue"
                  Text {
                      id : t1
                      anchors.centerIn: parent
                      text : rep.count
                  }
              }
          }
      
          Column {
              width: parent.width/2
              height: parent.height
              spacing: 3
              id : c1
              Repeater{
                  id : r1
                  model: 4
                  delegate: comp
                  Component.onCompleted: {
                      for(var i=0;i<4;i++)
                          r1.itemAt(i).rep = r1
                  }
              }
              Repeater{
                  id : r2
                  model: 10
                  delegate: comp
                  Component.onCompleted: {
                      for(var i=0;i<10;i++) {
                          r2.itemAt(i).rep = r2
                          r2.itemAt(i).color = "yellow"
                      }
                  }
              }
          }
      }
      

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        Nice. I simplified it a bit, passing only the count (not the entire repeater) to the Component, and it works just fine. Thanks!

        import QtQuick
        
        Window {
            width: 640
            height: 480
            visible: true
        
            Component {
                id : component
                Rectangle {
                    property int repeaterCount
                    width: 150; height: 50; color: "blue"
                    Text {
                        id : t1
                        anchors.centerIn: parent
                        text : repeaterCount
                    }
                }
            }
        
            Column {
                Repeater {
                    id : repeater1
                    model: 4
                    delegate: component
                    Component.onCompleted: {
                        for (var i = 0; i < repeater1.count; i++) {
                            itemAt(i).repeaterCount = count
                        }
                    }
                }
                Repeater {
                    id : repeater2
                    model: 10
                    delegate: component
                    Component.onCompleted: {
                        for (var i = 0; i < repeater2.count; i++) {
                            itemAt(i).repeaterCount = count
                            itemAt(i).color = "yellow"
                        }
                    }
                }
            }
        }
        
        1 Reply Last reply
        0
        • mzimmersM mzimmers has marked this topic as solved on
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          Note that this only works if the model is static (doesn't change after the onCompleted).

          1 Reply Last reply
          1

          • Login

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