Accessing properties of button style from button
-
Hello,
I have a such a button:
@
Button {
id:btnPlayStop
style: ButtonStyle {
id: stylePlayStopbackground: Rectangle { Image { id: imgPlayStop source: "qrc:/images/btnPlay_disabled.png" anchors.centerIn: parent } } } }
@
My question is: how can I access to "source" of "imgPlayStop" in "btnPlayStop"
Could you please help me?Thank you!
-
Hello,
just use imgPlayStop.source for that, for example:
@function setSource(src){
imgPlayStop.source = src
}@ -
Hello onek24,
If I do like that there is an error :"ReferenceError: imgPlayStop is not defined"
-
I see, it looks like you can't access the backgroud-component the way we are trying to do. You can go ahead and create a variable for your source and use it instead:
@Button {
id:btnPlayStop
property string src: "qrc:/images/btnPlay_disabled.png"
style: ButtonStyle {
id: stylePlayStopbackground: Rectangle { Image { id: imgPlayStop source: btnPlayStop.src anchors.centerIn: parent } } } }@
@function setSource(src)
btnPlayStop.src = src
}@ -
Yes, I also use this work-around, but is there any way to access the imgPlayStop from btnPlayStop without binding like that. I mean we can access like: btnPlayStop.stylePlayStop.imgPlayStop ?????
-
I currently don't know of another method, maybe someone else knows a solution.
-
Thanks for your answer! I always feel difficult to access the properties of child component. I hope I can find more documentation about this. I'm so confused now.
-
You're welcome, i'm sorry that i couldn't help you out more.
style: and background: are properties, so the problem might be the accessing of a component which is the value of these properties?