I need to get width and height of a Rectangle in Component.OnCompleted
handler but if i print the same i am getting some unknown values, Follow
The parent
of items, nested directly in the window is not the window, but the window's contentItem
.
Try this instead:
Rectangle{
id:rect
width: appWindow.width * 0.75
height: appWindow.height * 0.70
}
The same applies for your "full code":
Rectangle{
id:rectParent
width:appWindow.width * 0.75
height: appWindow.height * 0.70
Rectangle{
id:rectChild
width:parent.width * 0.75
height: parent.height * 0.70
Component.onCompleted: {
console.log("Width=",width) //prints "Width= 337.5"
}
}
}
You can use parent
in the second rectangle, because its parent will be the first rectangle, but since the first is nested inside the window, it needs to refer to the window instead of its parent to get property sized.