Unsolved How to display and change two values from a single item in QListView
I am creating a QStyledItemDelegate and need two display two values (QString and QDateTime) in a single item and need two change both in a database after editing the text displayed. Is there any way two achieve this?
You can overwrite the setModelData to do that.
Thanks for your response!
I think I expressed myself very vaguely. What I want to achieve exactly is that I want to use a QSqlQueryModel to fill a QListView with items. Each item should get a value from two columns, which should both be changed after editing in the model. I know that I can use setModelData to overwrite values from the model with those from the editor widget.
JonB last edited by
Then kind of: what is your exact question, what answer are you looking for? There won't (I imagine) be an example of this out there, as it;s a rather unusual thing to do.
I think your
QSqlQueryModelshould map one-to-one with the actual columns in the database, for simplicity. What you then do with that as you map to/from the view/styled delegate is up to you. It sounds like your requirement may be a bit messy, but presumably it can be done.
I don't know, but it might help break it down if you interposed a
QAbstractProxyModelbetween the SQL model and the view. Starting from a
QIdentityProxyModel. You could then do your "conglomeration"/"split" of the dual columns there. Since data items can be any
QVariant, I'm thinking a
QPairfor the string-date pair. So it gets presented as one column item to/from the view, but separate columns to/from the database. If it's only a
QListViewand not a full
QTableViewmaybe I'm over-engineering and you can do it directly, but it's a thought.