PDA

View Full Version : How to access child properties from another child in QML



hparihar88
12th June 2013, 10:42
I want to change image(child of Rectangle) on mouse hover of MouseArea(child of Rectangle)
here is my code:
Rectangle
{
width: 600; height: 400
Row
{
id: myRow; spacing: 5; x: 50; y: 200
Repeater
{
id: myRepeater; model: 10
Rectangle
{
width: 100; height: 100;
property int myIndex: index
Image
{
source: "../GrayPoint.png"
}
MouseArea
{
id: mouseArea; anchors.fill: parent; hoverEnabled: true
onEntered:
updateUI( parent )
}
}

}
}
function updateUI( theParent )
{
theParent.childAt( 0, 0 ).source = "../RedPoint.png"
}
}

anda_skoa
13th June 2013, 10:55
Add a property to the parent and use it in both children.

Cheers,
_

wysota
13th June 2013, 11:46
Or refer to the item using its id:

Image {
source: ma.containsMouse ? "../RedPoint.png" : "../GrayPoint.png"
}
MouseArea {
id: ma
hoverEnabled: true
anchors.fill: parent
}