PDA

View Full Version : color of table cells



rickym
22nd January 2007, 21:12
Hi all,

maybe this is a repetition but I just could not get ot working. My question is simple:
just wanted to make so cells in the QTableView colored when the data fulfill certain conditions.

atm, my code looks like this:


void MainInterface::colorWarning()
{
int rownumber;
for(rownumber=0;rownumber<=100; rownumber++) {
QModelIndex idindex = mui.tableViewPersonTable->model()->index(rownumber, 9, QModelIndex())
if (idindex.isValid()){
QString dateString = idindex.data().toString();
QDate date = QDate::fromString(dateString, "yyyy-MM-dd");
QDate today = QDate::currentDate();
int daysafter = date.daysTo(today);
if (daysafter >= 30) {
mui.tableViewPersonTable->model()->setData(idindex, Qt::green, Qt::BackgroundRole))
}
}
}
}

thanks!!!

e8johan
24th January 2007, 10:20
Have you tried listening for a dataChanged signal (using a QSignalSpy). If the signal is not emitted explicitly from the setData method the view will never know that the data has changed.