November 10, 2011

Adi Adi
Lab Rat
205 posts

How to change the text color in QTableView

 

Hi All

I want to change the color of the text in some cells in QTableView.
How to do this?

2 replies

November 10, 2011

veeeee_d veeeee_d
Lab Rat
56 posts

Check QItemDelegate::drawDisplay.

November 10, 2011

Andre Andre
Area 51 Engineer
6031 posts

Rajveer, are you using a QTableView this time, or are you really using a QTableModel as you were in your last questions?

In the latter case, you should check out setting the Qt::ForeGroundRole on the cell you want to color.

  1. QTableWidgetItem* myItem; //set it to the item you want to manipulate
  2.  
  3. myItem->setForeground(QColor::fromRgb(255,0,0)); //make this item red.

If you really have your own model, then you need to return this color as a variant from your data() method, but I doubt you are doing that.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

 
  ‹‹ mixing Qt3 and Qt4 core in an application      qreal in QVariant ››

You must log in to post a reply. Not a member yet? Register here!