How to Assing an id property for dynamically created element.
-
Mr xsacha
You have no way to dynamically make a grid using ListModel/Delegate with one dataset!! so you have to draw the grid and populate it with suitable data.the cell has to make sense to the user actions regardless of the GridComponent so the need to Know the id is very required
-
You can add elements to a model at any time (dynamically).
Each element can be uniquely identified with a property (eg. name) or an index.I don't understand what you mean but I assume you think the model is limited to static ListElements?
You can use insert (or append):
@fruitModel.insert(2, {"cost": 5.95, "name":"Pizza", "shape":"Rectangle"})@You can dynamically change properties:
@fruitModel.setProperty(index, "cost", cost * 2)@You can then refer to these elements:
@index@
@grid.indexAt(mouseX, mouseY)@
@fruitModel.get(index).name@ -
but you have no way to make a grid using one model??
-
@
Component {
id: widgetDelegate
Rectangle {
width: 80; height: 80
radius: shape == "Circle" ? 80 : 0
}
}
GridView {
model: WidgetModel { id: widgetModel }
delegate: widgetDelegate
}@This is a GridView with one model?
The dataset can come from an online feed, from XML (like Flickr/Facebook/Twitter or a personal database), or a simple ListModel type.
Did you mean multiple models?
-
suppose you has a database table Persons(id,name,phone,address,JobTitle,etc) . Gridview has one model , and one model can display predefined data row , suppose I made the following query (SELECT ID,ADDRESS FROM PERSONS) ???? and in another time the query (SELECT ETC FROM PERSONS)??
-
Yes, I have done this a few times.
Have a look at the Twitter app in the SDK that uses very similar 'SELECT' style commands via an XML Model.
Alternatively, you can use a ListModel and sort it yourself.
Remember, you can change the model at any time and you can have temporary models that hold all the information but are never used if you like. -
Here's an example to demonstrate: SELECT "flagged" FROM name IN widgetmodel (pseudo sql query)
Using a ListModel:@GridView {
model: WidgetModel { id: widgetModel }
delegate: widgetDelegate
MouseArea {
id: selectFlaggedFromName
anchors.fill: parent
onClicked: {
for (var i = 0; i < widgetModel.count; i++)
{
if (widgetModel.get(i).name != "flagged")
widgetModel.remove(i--)
}
}
}
}@Working fine here.
-
thank you xsacha I will review that and of course feed you back about?
-
This has been made in to a Wiki Entry: http://developer.qt.nokia.com/wiki/Real-time_Sorting_and_Filtering_of_a_GridView
Enjoy!
-
assistant say:
*QAbstractItemModel presents a hierarchy of tables, but the views currently provided by QML can only display list data. *