I am learning Qt and I have some difficulty. I was using QTableWidget and when an item receive a double click a change row color:
for (int j = 0; j < ui->tableWidget->horizontalHeader()->count(); j++) {
ui->tableWidget->item(row, j)->setForeground(color);
}
But now I am using QTableView, I created a QAbstractTableModel to this and work fine. I done some filters with QSortFilterProxyModel and work fine too. But I am not having success to change row color. I already tried things like this:
m_model.setData(m_model.index(1,2) , QColor(Qt::blue), Qt::BackgroundColorRole);
And not work. In model::setData() I wrote some debugs and it joins in function right, but not change color.
bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (data(index, role) != value) {
qDebug() << index << value << role;
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Debug output:
QModelIndex(1,2,0x0,MyModel(0x7fffffffe408)) QVariant(QColor, QColor(ARGB 1, 0, 0, 1)) 8