01-16-2013 02:44 PM
i have a class that returns information about the a set of items.
foo bar = new foo("item1", true);
QString myText = bar.text; //myText = "item1"
bool myBool = bar.active; // myBool = true
listItemComponents: [
ListItemComponent {
type: "item"
Container {
layout: StackLayout { orientation : LayoutOrientation.LeftToRight }
ImageView {
preferredWidth: 40
scalingMethod: ScalingMethod.AspectFit
verticalAlignment: VerticalAlignment.Bottom
imageSource: {
if (ListItemData.active) { imageSource = "asset:///images/on.png" ; }
else { imageSource = "asset:///images/off.png" ; }
}
}
Label {
text: ListItemData.text
}
Label {
text: "(" + ListItemData.active + ")"
}
}
}
]
Solved! Go to Solution.
01-17-2013 02:41 AM
You have imageSource 2 times. One outside the if, one inside the if.
imageSource: {
if (ListItemData.active) { imageSource = "asset:///images/on.png" ; }
else { imageSource = "asset:///images/off.png" ; }
}Try the next line
imageSource: "asset:///images/" + (ListItemData.active?"on":"off") + ".png"
It's a bit shorter and it works for me.
01-17-2013 05:09 AM
I think you can't use if else statement. Try the code below instead :
imageSource: ListItemData.active ? "asset:///images/on.png" : "asset:///images/off.png"
01-17-2013 05:11 AM
I allready replied to that with the same solution
.
01-17-2013 05:14 AM