Image source property change from javascript
-
wrote on 7 Apr 2011, 08:38 last edited by
Hi, I didnt find anything what is useful especially for this question.
I have an Image in a qml, and I have an other qml with a javascript code. How can I access the Image in an other qml and change its properties from javascript if a condition will be true?
Have you any suggestion in this?
Thank you! -
wrote on 7 Apr 2011, 08:53 last edited by
Reference the id, and set the new source. Or, better yet, make the source URL a property of in your other QML file, and bind the source property of the image to that property.
-
wrote on 7 Apr 2011, 09:04 last edited by
I am new to Qt and cant imagine sure what Ive to do.
Could you write an example please? -
wrote on 7 Apr 2011, 11:50 last edited by
For the example off course I think only that few essential rows which is needed for me in this problem.
-
wrote on 7 Apr 2011, 12:05 last edited by
Something along these lines:
Other.qml:
@
Item {
id: myOtherComponent;
property string imageSource;// your javascript will modify the imageSource property when appropriate
}
@main.qml:
@
Item {
Other {
id: myMagicJavaScriptStuff;
}Image {
id: theImage;
source: myMagicJavaScriptStuff.imageSource;
}
}
@Something along those lines would work...
-
wrote on 7 Apr 2011, 21:46 last edited by
Thank you! I'll test it as soon as I can!
-
wrote on 8 Apr 2011, 10:55 last edited by
The above code didnt work for me. But I had an idea and made a cute code. Please take a look to the following part of qml:
@
Image {
source: getOutImgSource()function getOutImgSource() {
if (loggedIn) return "images/menu-08Loged.png";
else return "images/menu-08.png";
}
}
@But it doesnt work to! It looks like the qmlviewer doesnt refresh the graphics. Is it possible?
Have you any idea?
Edit: please use @ tags around code sections to format them; Andre
4/7