12-26-2012 09:05 PM
Hi,
I have a list with JSON data fed into it. In the StandardListItem I have an Image source. Now through the Action overflow menu, I want to be able to toggle the image source to on/off. Is there anyway to do this?
My code is below. In the ActionItem with id: toggleListFlags, the text changes fine of the Action item, but the image of the StandardListItem does not toggle. Any ideas?
TabbedPane {
property variant countryView
id: mainTabPage
showTabsOnActionBar: true
Tab {
id: countryTab
title: qsTr("Countries")
NavigationPane {
id: countryNav
Page {
id: countryPage
Container {
ListView {
id: countryList
objectName: "countryList"
dataModel: dataModel
listItemComponents: [
ListItemComponent {
type: "item"
StandardListItem {
id: mainCountryList
title: ListItemData.name
imageSource: "asset:///images/picture1.png"
}
}
]
onTriggered: {
...
}
}
attachedObjects: [
GroupDataModel {
...
},
DataSource {
...
}
]
}
actions: [
ActionItem {
id: toggleListFlags
title: qsTr("Hide Flags")
onTriggered: {
if (toggleListFlags.title == "Hide Flags") {
toggleListFlags.title = "Show Flags"
mainCountryList.imageSource = null
} else if (toggleListFlags.title == "Show Flags") {
toggleListFlags.title = "Hide Flags"
mainCountryList.imageSource = "asset:///images/picture1.png"
}
}
}
]// End Actionitems
onCreationCompleted: {
...
}
}
attachedObjects: [
ComponentDefinition {
id: countryPageDefinition;
source: "countryDetail.qml"
}
]
}
}
}
}
12-27-2012 09:29 PM
Any idea anybody?
12-27-2012 10:40 PM
You cannot assign null for an imageSource. Now we are not able to use null keyword in QML. But I dont know how to replace it.
12-27-2012 11:05 PM
12-27-2012 11:11 PM
We can also use function resetImage() to resets the image on this list item to a default value of an empty image.
12-28-2012 02:33 AM
I'm not sure you can acces list item from page action item. but may be you can try property to change the list item value on the fly like this
TabbedPane {
property variant countryView
id: mainTabPage
showTabsOnActionBar: true
Tab {
id: countryTab
title: qsTr("Countries")
NavigationPane {
id: countryNav
Page {
id: countryPage
Container {
ListView {
id: countryList
property string imageUrl
objectName: "countryList"
dataModel: dataModel
listItemComponents: [
ListItemComponent {
type: "item"
StandardListItem {
id: mainCountryList
title: ListItemData.name
imageSource: ListItem.view.imageUrl
}
}
]
onTriggered: {
...
}
}
attachedObjects: [
GroupDataModel {
...
},
DataSource {
...
}
]
}
actions: [
ActionItem {
id: toggleListFlags
title: qsTr("Hide Flags")
onTriggered: {
if (toggleListFlags.title == "Hide Flags") {
toggleListFlags.title = "Show Flags"
countyList.imageUrl = ""
} else if (toggleListFlags.title == "Show Flags") {
toggleListFlags.title = "Hide Flags"
countryList.imageUrl = "asset:///images/picture1.png"
}
}
}
]// End Actionitems
onCreationCompleted: {
...
}
}
attachedObjects: [
ComponentDefinition {
id: countryPageDefinition;
source: "countryDetail.qml"
}
]
}
}
}
}
haven't try yet, but I think it should work ![]()
12-28-2012 05:34 AM
Frankly, I didn't try it but I don't think it works because QML don't realize "null" keyword
12-29-2012 08:49 PM - edited 12-29-2012 09:34 PM
@hakimrie
Hey,
Works well! Thanks!
-G
I think i spoke too early. The imageUrl should be pointing to an item link that is pulled from the JSON file I have. Just like I do this in the StandardListItem.
title: ListItemData.name
By declaring that outside, I can't pull that data.
Any idea?