[Moved] Set Graphic background SVG depending on conditional
-
I think I am going to ask a newbie question but here goes anyway.
I have created a working graphical item using layered SVG images. However I would like to change the first (background) layer depending on a conditional value set as a property.
Is there a way in Qt Quick to use QML for something like the C++ case statement where there is more than two values for the conditional. I.E. value 1 value 2 and value 3, etc. the condition ? operator seems to only give two choices (condition is true or false).
Depending on the conditional value (1,2,3, etc.) I intend to select the appropriate background SVG source rather than creating a unique item for each different value only changing the background.
-
You can use switch statements in QML as well (though there is a bug related to this at the moment; see http://bugreports.qt.nokia.com/browse/QTBUG-17012 for details). You can also use if/else if type constructs -- BoomBlock.qml from the samegame demo shows an example of this:
@
Image {
id: img
source: {
if(type == 0){
"pics/redStone.png";
} else if(type == 1) {
"pics/blueStone.png";
} else {
"pics/greenStone.png";
}
}
...
}
@Regards,
Michael