Answer the question
In order to leave comments, you need to log in
QML. repeater. How to find out the Index of each Repeater element?
A certain number of buttons are created using Repeater(ListModel). How to access a specific button and find out its parameters (X, Y)?
main.qml
Repeater {
model: buttons
buttons{
}
ListModel { // модель для кнопок
id: buttons
ListElement { model_button_text: "1"; }
ListElement { model_button_text: "2"; }
Button{
id: btn
Layout.preferredWidth: Screen.pixelDensity * 18
Layout.preferredHeight: Screen.pixelDensity * 21
Text{
anchors.centerIn: parent
text:model_button_text
font.pixelSize: Screen.pixelDensity * 5
color: "#056699"
font.bold: true
}
background: Rectangle{
color:"black"
//radius: 2
border.width: 2
border.color: "#056699"
}}
Answer the question
In order to leave comments, you need to log in
For example
SomeRoot {
id: root
Repeater {
model: buttons
delegate: SomeDelegate {}
}
Component.onCompleted: {
[].slice.call(root.children, 0, root.children.length - 1).forEach(function (item) { console.warn(item.x) });
}
Repeater {
id: repeater
model: buttons
delegate: SomeDelegate {}
Component.onCompleted: {
for (var i = 0; i < repeater.count; ++i)
console.warn(repeater.itemAt(i).x);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question