
This post has been edited 1 times, last edit by "Jean__" (Jan 10th 2008, 12:36pm)

This post has been edited 2 times, last edit by "flowerJT" (Jan 10th 2008, 7:39pm)
|
|
Source code |
1 2 3 4 5 6 7 8 |
class Delegate : public QItemDelegate
{
Q_OBJECT
public:
Delegate(QWidget *parent = 0) : QItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
};
|
|
|
Source code |
1 |
table->setItemDelegate(new Delegate); |
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//---------------------------------------------------
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QString val;
if (qVariantCanConvert<QString>(index.data()))
val = qVariantValue<QString>(index.data());
if (val == "1")
{
painter->fillRect(option.rect, option.palette.highlight());
}
else
QItemDelegate::paint(painter, option, index);
}
|