{
if(tb1[index.row()][index.column()] == 1)
{
QRectF source
(0.0,
0.0,
72.0,
70.0);
painter->eraseRect(option.rect);
if (option.
state & QStyle::State_Selected) painter->fillRect(option.rect, option.palette.highlight());
painter->drawImage(option.rect, Q1, source);
}
else if(tb1[index.row()][index.column()] == 2)
{
QRectF source
(0.0,
0.0,
72.0,
70.0);
painter->eraseRect(option.rect);
if (option.
state & QStyle::State_Selected) painter->fillRect(option.rect, option.palette.highlight());
painter->drawImage(option.rect, Q1, source);
}
else
{
if(!model->item(index.row(), index.column())->isEnabled())
QStyledItemDelegate::paint(painter, option, index);
else
{
painter->eraseRect(option.rect);
painter->fillRect(option.rect, Qt::white);
}
}
}
void Sphere::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if(tb1[index.row()][index.column()] == 1)
{
QImage Q1("Red Sphere.jpg");
QRectF source(0.0, 0.0, 72.0, 70.0);
painter->eraseRect(option.rect);
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
painter->drawImage(option.rect, Q1, source);
}
else if(tb1[index.row()][index.column()] == 2)
{
QImage Q1("Blue Sphere.jpg");
QRectF source(0.0, 0.0, 72.0, 70.0);
painter->eraseRect(option.rect);
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
painter->drawImage(option.rect, Q1, source);
}
else
{
QStandardItemModel *model = (QStandardItemModel*) index.model();
if(!model->item(index.row(), index.column())->isEnabled())
QStyledItemDelegate::paint(painter, option, index);
else
{
painter->eraseRect(option.rect);
painter->fillRect(option.rect, Qt::white);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks