Unsolved How to change TableView row colors which is using QSqlQueryModel
-
Hi,
I use Tableview like below;QSqlQueryModel *modelDosya; modelDosya->setQuery("SELECT sira_no, dosya_ad, dosya_yol FROM dosyalar " "WHERE kaynak_sn = " + index.sibling(index.row(), 0).data().toString() + " AND prog_kod = 59 " "ORDER BY sira_no;",baglanti::mdb()); ui->tVDosya->setModel(modelDosya); //Not working! modelDosya->setData(modelDosya->index(1,2),QBrush(Qt::red), Qt::BackgroundRole);
But color is not working. I tryed
QStandardItemModel *modelDetay;And color is working well.
Any solution for "QSqlQueryModel "
Regards,
Mucip:) -
Hi,
Either subclass QSqlQueryModel and handle that role yourself or use QIdentityProxyModel and handle the color in that model rather than the SQL model.
-
Dear @SGaist ,
I couldn't undestand very well. Please could you explain little bit more?.Regards,
Mucip:) -
What did you not understand ?
-
Dear @SGaist ,
Should I use QIdentityProxyModel?
But ı could not see setModel like easy way? I do not want to fill all cells one by one.Regards,
Mucip:) -
Should you ? That's up to you to decide.
Because the method name is setSourceModel
-
Dear @SGaist ,
Well, any sample code to use this?Regards,
Mucip:) -
You need a proxy model like Role Mask Proxy Model. You can find an example usage here