PDA

View Full Version : General Question about Qt4 Model/View



reed
5th May 2008, 20:54
Hello, I'm new. I've done a little Qt programming (Qt 3) but am now starting a program in which I want to more extensively use Qt 4 features, including the abstract model/view stuff.

My general question is this: are the items in a model assumed to have an order (be an order ed list, rather than an unordered set) -- since they are indexed by an integer this seems to be the case. And are integers always used, or could they have some other key like a string or variable size hash value? And if you sort items in a view, that pertains only to that view's display, not to the ordering in the model?

Thanks

Reed

wysota
5th May 2008, 21:37
My general question is this: are the items in a model assumed to have an order
A logical order (you have to be able to identify each of the items). You can present them in any way you want using a custom view.


And are integers always used, or could they have some other key like a string or variable size hash value?
You can order strings or hash values, so you can map it to integers easily. You just have to know which of two keys is earlier in the set and which is later.


And if you sort items in a view, that pertains only to that view's display, not to the ordering in the model?

It changes the order of items in the model (QAbstractItemModel::sort() is called). If you want to keep the order of the items, wrap your model into QSortFilterProxyModel and set that as the view's model.

reed
13th May 2008, 15:06
Thanks. I want the order to stay in the view, not change the model (since the model is fundamentally unordered). So the sort proxy sounds like what I want. (A sort proxy for each view.)