Can't get parent property value in if statement
-
I can't reach parent properties inside if statement and if condition .Properties from another qml items passed by id can't be read too. Here is the code:
Image {id: myImage antialiasing: true x: xCoordinate y: yCoordinate width: elementWidht height: elementHeight rotation: rotationAngle fillMode: cellFill smooth: cellSmooth source: "qrc:/pics/folder/Frame.svg" property string cname: "myImage" Component.onCompleted: { console.log(cname, "successfully created!"); } //print caption property alias text3: caption.text Text { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter id: caption //width: parent.width height: 29 color: "red" text: "dynamically changed text..." font.pointSize: 9 rotation: 360- parent.rotation //here parent rotation is 270 anchors.top: {if(parent.rotation ==180) {parent.top console.log("here1")} if(parent.rotation==0){parent.bottom // parent rotation is null here and go into if statement? console.log("here2" + parent.rotation) //gives null } if(parent.rotation==90){parent.right console.log("here3") } } }
}
-
@Deyan ah ok, I now see this is inside the anchors property.
Possible, that is messing things up! Because a local scope shouldn't mess this up.You can always refer to the item directly via the
id
,caption
ormyImage
-
I can't reach parent properties inside if statement and if condition .Properties from another qml items passed by id can't be read too. Here is the code:
Image {id: myImage antialiasing: true x: xCoordinate y: yCoordinate width: elementWidht height: elementHeight rotation: rotationAngle fillMode: cellFill smooth: cellSmooth source: "qrc:/pics/folder/Frame.svg" property string cname: "myImage" Component.onCompleted: { console.log(cname, "successfully created!"); } //print caption property alias text3: caption.text Text { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter id: caption //width: parent.width height: 29 color: "red" text: "dynamically changed text..." font.pointSize: 9 rotation: 360- parent.rotation //here parent rotation is 270 anchors.top: {if(parent.rotation ==180) {parent.top console.log("here1")} if(parent.rotation==0){parent.bottom // parent rotation is null here and go into if statement? console.log("here2" + parent.rotation) //gives null } if(parent.rotation==90){parent.right console.log("here3") } } }
}
-
@Deyan probably a transformation/cast error, try
console.log("here2", parent.rotation)
instead ofconsole.log("here2" + parent.rotation)
-
@J-Hilk I tried but again the value is 0. It is 0 inside if condition too, because console.log wouldn't be reached if parent.rotation was read correctly.
-
@Deyan ah ok, I now see this is inside the anchors property.
Possible, that is messing things up! Because a local scope shouldn't mess this up.You can always refer to the item directly via the
id
,caption
ormyImage
-
@Deyan ah ok, I now see this is inside the anchors property.
Possible, that is messing things up! Because a local scope shouldn't mess this up.You can always refer to the item directly via the
id
,caption
ormyImage