-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitem_delegates.h
50 lines (41 loc) · 1.58 KB
/
item_delegates.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef ITEM_DELEGATES_H
#define ITEM_DELEGATES_H
#include <QStyledItemDelegate>
#include <QDebug>
#include <QPainter>
#include <QApplication>
class ColorDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
void paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const {
QStyleOptionViewItem op(option);
QString colorValue = index.data(Qt::DisplayRole).toString();
QColor color = QColor(colorValue);
op.backgroundBrush.setColor(color);
op.backgroundBrush.setStyle(Qt::BrushStyle::SolidPattern);
op.font.setBold(true);
op.palette.setColor(QPalette::Text, QColor("#ffffff"));
painter->fillRect(op.rect, op.backgroundBrush);
QStyledItemDelegate::paint(painter, op, index);
}
};
class CheckBoxDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
void paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const {
QStyleOptionViewItem op(option);
QStyleOptionButton btnStyle;
bool isActive = index.data(Qt::DisplayRole).toBool();
if (isActive) {
btnStyle.state = QStyle::State_On;
} else {
btnStyle.state = QStyle::State_Off;
}
btnStyle.rect = option.rect;
btnStyle.rect.setLeft(btnStyle.rect.left() + 20);
QApplication::style()->drawControl(QStyle::CE_CheckBox, &btnStyle, painter);
}
};
#endif // ITEM_DELEGATES_H