PDA

View Full Version : How to change text displayed in multiple cells in QTableView?



adutzu89
13th February 2014, 11:46
I have a QTableView set with QSqlQueryModel, it has multiple columns from which the last 2 columns have values 0 and 1(both columns have cells with 0 and 1, and not 1 column with 0 and what column with 1).
I would like to replace 0=No and 1=Yes, how can I achieve this?
My main issue is with finding those cells as I found most examples using delegates but those examples are about editing the cells you want and know.

Any help is appreciated.

anda_skoa
13th February 2014, 12:47
There are many possible ways to do that.

One is to derive from QSqlQueryModel and reimplement the data() method.
When DisplayRole values of those two columns are requested, you get the numerical value from the base class and the return the respective string.

Cheers,
_

adutzu89
14th February 2014, 08:52
Thank you for your answer, atm I managed to solve it easier by using replace function inside MySql query, I will try experimenting with delegates until I can understand them properly, because in the near future I would want to add some buttons inside the view.