QAbstractItemDelegate and QLinearGradient
Bonjour,
I've implemented a delegate (inhereted from QAbstractItemDelegate) in a QtableView in order to show the data as a bar chart.
Code:
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();
gradient.
setColorAt(0,
QColor(42,
142,
220) );
gradient.
setColorAt(0.5,
QColor(11,
90,
163) );
gradient.
setColorAt(1,
QColor(4,
24,
40) );
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
Re: QAbstractItemDelegate and QLinearGradient
The view is populated this way:
Code:
Delegate delegate;
table.setItemDelegateForColumn(1, &delegate)
for(int i =0; i<totalFile; ++i)
{
model.setItem(r, 0, item);
}
table.setModel(&model);
Re: QAbstractItemDelegate and QLinearGradient
It's was just a problem of coordonates in QlinearGradient.