OK, ich denke ich habs. Mein einziges Problem was ich noch habe ist, das der Hintergrund wo mein Delegate wirkt, keine Farbe mehr hat.
hier der relevante Codeteil:
Code: Alles auswählen
void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
if (index.column() != 1) {
QItemDelegate::paint(painter, option, index);
}
else {
QAbstractItemModel *model = (QAbstractItemModel *)index.model();
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
(option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled;
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
int state = model->data(index, Qt::DisplayRole).toInt();
QString s1 = model->data(index, Qt::BackgroundRole).toString();
model->setData(index, QColor(s1), Qt::BackgroundRole); // Funktioniert nicht
/*
// Funktioniert auch nicht
QBrush brush = painter->brush();
brush.setStyle(Qt::SolidPattern);
brush.setColor(QColor(s1));
painter->setBrush(brush);
*/
int rating = 0;
if(state & 1) {
qDebug() << "Found (!)";
rating ++;
}
if(state & 2) {
qDebug() << "Found (!!)";
rating ++;
}
int width = qi_warning.width();
int height = qi_warning.height();
int x = option.rect.x();
int y = option.rect.y() + (option.rect.height() / 2) - (height / 2);
for (int i = 0; i < rating; ++i) {
if(i == 0) {
if(state & 1)
painter->drawPixmap(x, y, qi_info);
else if(state & 1)
painter->drawPixmap(x, y, qi_warning);
}
else if(i == 1) {
if(state & 1)
painter->drawPixmap(x, y, qi_warning);
}
x += width;
}
drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
}
QPen pen = painter->pen();
painter->setPen(option.palette.color(QPalette::Mid));
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
painter->setPen(pen);
}
Lg NoRulez