Home > other >  Qtableview can set the color of each cell? Or set the color of each row?
Qtableview can set the color of each cell? Or set the color of each row?

Time:09-26

Qtableview can set the color of each cell? Or set the color of each row?

CodePudding user response:

Combined with the model is used, can,

CodePudding user response:

See example: $${QT_DIR} \ examples, widgets, tutorials, modelview

CodePudding user response:

Check the Qt: : ItemDataRole types in Qt: : BackgroundRole in model setData (index, QBrush (QColor (" # 0 x00ff00 ")), Qt: : BackgroundRole);

CodePudding user response:

3/f is the way you said a test?

CodePudding user response:

This is my way the implementation of the http://www.cnblogs.com/justwake/archive/2013/06/02/3113634.html

CodePudding user response:

QAbstractItemModel http://www.cnblogs.com/justwake/archive/2012/12/22/justwake_3.html

CodePudding user response:

Set the cell color, it is set up on the Item of the Model, to get a case of Item (QStandardItem Item) QBrush brush=QColor (255, 0, 0). Item. SetBackground (brush);//set to red QBrush br=QColor (255, 255, 0). Item. SetForeground (br);//font for yellow

CodePudding user response:

The
reference 3 floor response:
check the Qt: : ItemDataRole types in Qt: : BackgroundRole in model setData (index, QBrush (QColor (" # 0 x00ff00 ")), Qt: : BackgroundRole);


3/f is available, thanks. Rewrite the data originally, find so you can

QStandardItemModel * m_Model;//data model

//selectedIndexes () the entire line, corresponding selectedRows () the first cell
QModelIndexList indexList=UI - & gt; TableView - & gt; The selectionModel () - & gt; SelectedIndexes ();
Foreach (QModelIndex index, indexList)
{
M_Model - & gt; SetData (index, QBrush (QColor (Qt: : darkGray)), Qt: : BackgroundRole);
}
  • Related