I am trying to dynamically build a matrix of the same type of items in my QML application and keep it dynamic, so that you can change the number of rows and columns in a c++ file anytime. This has been working well, but now, to access them individually, I want to give them dynamic names. Therefore I nested two repeaters and tried to set the objectName as in the following:
Repeater{
id: rows
model: Matrix1.row //number of rows in Matrix1-Object
Repeater{
id: columns
model: Matrix1.column //number of columns in Matrix1-Object
RepeatedItem{
objectName: (index) +"."+ (rows.index) //matrix elements are
supposed to be numbered x.y because of the nested repeaters, e.g.
0.0 for the first element
}
}
}
Unfortunately I seem to have no access to the outer index. The first value is shown, the second value is represented by the String undefined in the TextArea of my GUI. In case I add a new property to the outer Repeater and set it the same value as index, it will be set once and keep the first value (0) for each repeated row.
Is it impossible to dynamically reach this outer index value somehow? Or does anyone know a better way to dynamically create two-dimensional arrays of items in QML which are individually accessable?
The
index
property is a context property. You can store it to an ordinary property, so you can access it from another context:Personally I have solved it using just one Repeater with the following model property: Matrix1.column * Matrix1.row. Furthermore I realized that for my purpose it is fine just calculating row and column of the clicked element with %- and /- operators, row number, column number and the recently accessed index.