QSqlQueryModel subclass && QLinearGradient in a cell
-
Hi all,
I subclassed a QSqlQueryModel to change some color of a cell in a QTableView.This is my code:
@
QVariant CustomQueryModel::data(const QModelIndex &index, int role) const
{
switch(role)
{
case Qt::BackgroundRole:
if(index.column()==8 && index.isValid())
{
QLinearGradient grad(0,0,1,0);
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
grad.setColorAt(0.0, QColor(200,50,50));
grad.setColorAt(0.5, QColor(50,200,50));
grad.setColorAt(1.0, QColor(50,200,50));
return QBrush(grad);
}
break;
default:
return QSqlQueryModel::data(index,role);
}
return QSqlQueryModel::data(index,role);
}@
As you can see I want a linear gradient in the cells on column 8.
The problem is that the gradient isn't displayed, it only set the cell's color on QColor(200,50,50).
The gradient is shown correctly if I set it on the column 1:
@
QVariant CustomQueryModel::data(const QModelIndex &index, int role) const
{
switch(role)
{
case Qt::BackgroundRole:
if(index.column()==1 && index.isValid())
{
QLinearGradient grad(0,0,1,0);
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
grad.setColorAt(0.0, QColor(200,50,50));
grad.setColorAt(0.5, QColor(50,200,50));
grad.setColorAt(1.0, QColor(50,200,50));
return QBrush(grad);
}
break;
default:
return QSqlQueryModel::data(index,role);
}
return QSqlQueryModel::data(index,role);
}
@
it seems to be a coordinates problem but I don't know how to solve it.Can you help me?
Thanks