Bonjour,

I've implemented a delegate (inhereted from QAbstractItemDelegate) in a QtableView in order to show the data as a bar chart.

Qt Code:
  1. void Delegate:: paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
  2. {
  3. int value = index.model()->data( index, Qt::DisplayRole ).toInt();
  4. double percent = double(value)/100.0;
  5.  
  6. painter->save();
  7.  
  8. QLinearGradient gradient( QPoint ( option.rect.x(), option.rect.y() ), QPoint ( option.rect.x() , option.rect.height() ) );
  9. gradient.setColorAt(0, QColor(42, 142,220) );
  10. gradient.setColorAt(0.5, QColor(11, 90,163) );
  11. gradient.setColorAt(1, QColor(4, 24,40) );
  12. QBrush brush(gradient);
  13. painter->setBrush(brush);
  14. painter->drawRect(option.rect.x(), option.rect.y() , int(percent*(option.rect.width())), option.rect.height() );
  15.  
  16. painter->restore();
  17.  
  18. }
To copy to clipboard, switch view to plain text mode 

The gradient is not rendered at all. Instead Ive got a plain color.

Any ideas ?

Regards