Problem with row coloring in qtableview
Hello,
I am using following code to assign data and color to contents of QTableView:
Code:
for(y=0; y<7; y++)
{
if(y==6)
{
if(nepopolno)
item->setData("krizec",Qt::DisplayRole);
else
item->setData("kljukica",Qt::DisplayRole);
}
else
item->setData(ukaz.value(y).toString(),Qt::DisplayRole);
item->setData(ukaz.value(6).toString(),Qt::UserRole);
item->setBackground(Qt::red);
model.setItem(vrsta,y,item);
}
Variable y represents column as you can see. Problem I face is that only first column is colored. If I debug with debugger, then I see that item->setBackground() method is certainly called for every QStandardItem of model that is assigned to QTableView.
Any clues how to write this code correctly? Or is there some other issue with Qt?
Re: Problem with row coloring in qtableview
Try writing a simple delegate
See the Qt examples