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. Getting the index of the outer Repeater of nested Repeater
Forum Updated to NodeBB v4.3 + New Features

Getting the index of the outer Repeater of nested Repeater

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 2.0k 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.
  • S Offline
    S Offline
    Snotboogie
    wrote on 3 Jul 2017, 19:56 last edited by
    #1

    I have a repeater inside another repeater.

    import QtQuick 2.6
    import QtQuick.Window 2.2
    
    Window {
        id: win
        visible: true
        width: 640
        height: 480
    
    
        Column {
            Repeater {
                model: 10
                Row {
                    Repeater {
                        model: 2
                        Text {
                            text: "I'm item " + index + " "
                            MouseArea {
                                anchors.fill: parent
                                onClicked: console.log(index)
                            }
                        }
                    }
                }
            }
        }
    }
    

    The window looks something like this:

    I'm item 0 I'm item 1
    I'm item 0 I'm item 1
    I'm item 0 I'm item 1 <------
    I'm item 0 I'm item 1
    I'm item 0 I'm item 1
    I'm item 0 I'm item 1
    I'm item 0 I'm item 1
    I'm item 0 I'm item 1
    I'm item 0 I'm item 1
    I'm item 0 I'm item 1

    Let's say I clicked on the item by that arrow, currently I can get column's index. How can I find the row's index?

    Thanks in advance

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 3 Jul 2017, 20:52 last edited by A Former User 7 Mar 2017, 20:59
      #2

      Hi!

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.3
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Column {
              Repeater {
                  model: 10
                  Row {
                      property int rowIndex: index
                      Repeater {
                          model: 10
                          Rectangle {
                              property int columnIndex: index
                              width: 60
                              height: 30
                              color: "orange"
                              border.width: 1
                              Text {
                                  anchors.centerIn: parent
                                  text: rowIndex + ", " + columnIndex
                              }
                          }
                      }
                  }
              }
          }
      }
      

      Edit: oops, rows and columns were interchanged.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Snotboogie
        wrote on 3 Jul 2017, 21:42 last edited by
        #3

        Thank you.

        1 Reply Last reply
        0

        1/3

        3 Jul 2017, 19:56

        • Login

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