-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusindicatordelegate.cpp
35 lines (28 loc) · 1.13 KB
/
statusindicatordelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "statusindicatordelegate.h"
StatusIndicatorDelegate::StatusIndicatorDelegate(QWidget *parent) :
QStyledItemDelegate(parent)
{
}
void StatusIndicatorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
painter->save();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(Qt::NoPen);
painter->translate(option.rect.x(), option.rect.y());
QPixmap stateIcon;
if (index.data().isNull()) {
stateIcon.load(":/images/fail.png");
} else {
stateIcon.load(":/images/ok.png");
}
painter->drawPixmap((option.rect.width() - stateIcon.width()) / 2, (option.rect.height() - stateIcon.height()) / 2, stateIcon.width(), stateIcon.height(), stateIcon);
painter->restore();
}
QSize StatusIndicatorDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
return QSize(option.rect.width(), option.rect.height());
}