PDA

View Full Version : Subclass QListView to show two colums in one



Mookie
22nd June 2007, 17:33
I have two views connected to the same model. One is a QListView that shows all the rows, the other is a widget with column fields which I'll call my EditBox.

I am attempting to subclass QListView and modify it's display. The default QListView implementation shows only the column specified by modelColumn(). Mine needs to combine two columns into one.

"lastname, firstname"

When I've asked people about tackling this, most answers are "modify the model". This is a display issue and the view really should handle this. Edits to the firstname or lastname fields will need to trigger a dataChanged() signal in the view, so duplicating the data storage is not preferred.

My issue is knowing what to reimplement in QListView to override the display. Hopefully I can then dive into the model and pull out the required fields from the row specified by the index given (e.g. don't show lastname only, but go find firstname and append it to the end with a comma just before doing your layout). paint() is so low level. There's got to be a better place.

I have read everything I could on delegates, but I am a bit confused if they handle the display as well as editing. This will have no editing in the QListView. It will be read-only.

So, where should I look? View or Delegate?
Does anyone have any examples? (The spin box example in the tutorials isn't much help)
It should be pre-layout, obviously.

jacek
22nd June 2007, 22:50
How about implementing a proxy model?

Mookie
23rd June 2007, 02:12
I had considered this, but kept coming back to the "View/Model" format. From what I'm seeing in the QListView source code this isn't going to just be reimplementing a few member functions.

Yes, this would probably be the cleanest solution from what I'm seeing.