PDA

View Full Version : QListView with QSqLite and special format



Cerberus
11th October 2015, 21:59
I have a QListView which I fill with a QSqlQueryModel that select datasets from the QSqLite database.
The datasets I get have two columns:


| msg | ownership |
----------------------
| test1 | 0 |
| test2 | 1 |
| test3 | 1 |
| test4 | 0 |
----------------------



The ownership specifies if the messages was sent (0) or received (1).
When I fill the QListView with the data I don't wanna display the ownership, but according to it set the text color and perform an alignment.
e.g. it should look something like this



text1 <-- color red
text2 <-- color green
text3 <-- color green
text4 <-- color red




Does anyone know how to do this?

anda_skoa
12th October 2015, 00:55
Three options

1) use an item delegate that uses the ownership value and decides how to draw on that
2) derive from QSqlQueryModel and reimplement data() to answer for the alignment role and background role depending on the value of ownership
3) do the same thing with a class derived from QIdentityProxyModel with the QSqlQueryModel as the source.

Cheers,
_