How to display and change two values from a single item in QListView
-
Hi,
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. -
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.@myShrimp
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
QSqlQueryModel
should 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
QAbstractProxyModel
between the SQL model and the view. Starting from aQIdentityProxyModel
. You could then do your "conglomeration"/"split" of the dual columns there. Since data items can be anyQVariant
, I'm thinking astruct
/QPair
for 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 aQListView
and not a fullQTableView
maybe I'm over-engineering and you can do it directly, but it's a thought.