Cześć!
Jak z Component
profesjonalniej odwołać się do GridView?
Aktualnie wpisuję np. parent.parent.parent...
lecz niezbyt mi się to podoba.
Nie chcę tego robić poprzez id, ponieważ Component
będzie w osobnym pliku.
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
ListModel {
id: listModel
ListElement{ name: "A" }
ListElement{ name: "B" }
ListElement{ name: "C" }
ListElement{ name: "D" }
}
Component {
id: componentDelegate
Rectangle {
width: parent.parent.cellWidth *0.9 // pp
height: parent.parent.cellHeight*0.9 // pp
color: "#40808080"
radius: 5
Text {
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
text: name
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.parent.parent.currentIndex = index // ppp
}
}
}
}
GridView {
anchors.fill: parent
cellHeight: 48
cellWidth: 48
id: gridView
model: listModel
delegate: componentDelegate
highlight: Item{
Rectangle {
anchors.fill: parent
color: "red"
radius: 5
}
}
}
}