PDA

View Full Version : Models and item views



gonemad
29th February 2012, 17:07
Hi.

I'm developing an application for managing contacts and other types of data. I've sub classed QAbstractItemView to make my ContactModel and I've got my contact list working with a QListView.

I want to show a more detailed view of the contact when double clicked in the list and wonder how I would do that for a single item of the model. It seems to me like the models in Qt are made for lists of data rather than a row from the list.

Thanks!

wysota
29th February 2012, 17:59
IIt seems to me like the models in Qt are made for lists of data rather than a row from the list.

Not really. If you want to somehow display the data from the model then query the model for the data. How to do that depends how you implemented your model. If you used multiple columns to store the data then query columns of the row, if you have just one column but multiple roles holding the data then query the first column for the roles you need.

gonemad
29th February 2012, 18:28
So the best way to do this, will be implementing user roles based on the fields I want to view?

i.e

ContactModel->data(index, ContactModel::NameField)

wysota
29th February 2012, 18:53
There is no single best way to do it. It all depends on your needs. Using custom roles is a good approach if you don't care about showing all the data in the view (at least not without implementing a custom delegate).