toutarrive
12th February 2010, 11:13
Bonjour,
I've implemented a delegate (inhereted from QAbstractItemDelegate) in a QtableView in order to show the data as a bar chart.
void Delegate:: paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
int value = index.model()->data( index, Qt::DisplayRole ).toInt();
double percent = double(value)/100.0;
painter->save();
QLinearGradient gradient( QPoint ( option.rect.x(), option.rect.y() ), QPoint ( option.rect.x() , option.rect.height() ) );
gradient.setColorAt(0, QColor(42, 142,220) );
gradient.setColorAt(0.5, QColor(11, 90,163) );
gradient.setColorAt(1, QColor(4, 24,40) );
QBrush brush(gradient);
painter->setBrush(brush);
painter->drawRect(option.rect.x(), option.rect.y() , int(percent*(option.rect.width())), option.rect.height() );
painter->restore();
}
The gradient is not rendered at all. Instead Ive got a plain color.
Any ideas ?
Regards
I've implemented a delegate (inhereted from QAbstractItemDelegate) in a QtableView in order to show the data as a bar chart.
void Delegate:: paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
int value = index.model()->data( index, Qt::DisplayRole ).toInt();
double percent = double(value)/100.0;
painter->save();
QLinearGradient gradient( QPoint ( option.rect.x(), option.rect.y() ), QPoint ( option.rect.x() , option.rect.height() ) );
gradient.setColorAt(0, QColor(42, 142,220) );
gradient.setColorAt(0.5, QColor(11, 90,163) );
gradient.setColorAt(1, QColor(4, 24,40) );
QBrush brush(gradient);
painter->setBrush(brush);
painter->drawRect(option.rect.x(), option.rect.y() , int(percent*(option.rect.width())), option.rect.height() );
painter->restore();
}
The gradient is not rendered at all. Instead Ive got a plain color.
Any ideas ?
Regards