-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortdrawdelegate.cc
37 lines (32 loc) · 1.2 KB
/
sortdrawdelegate.cc
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
#include "sortdrawdelegate.h"
#include <QPainter>
namespace Drawing {
SortDrawDelegate::SortDrawDelegate(QObject* parent)
: QAbstractItemDelegate(parent){
}
void SortDrawDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
// if(option.state & QStyle::State_Selected) {
// painter->fillRect(option.rect, option.palette.highlight());
// }
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(QColor(0,255,0,100));
if (option.state & QStyle::State_Selected) {
painter->setBrush(QBrush(QColor(255, 255, 0, 100)));
} else {
painter->setBrush(QBrush(QColor(255, 0, 0, 100), Qt::SolidPattern));
}
int size = index.data().toInt();
int width = size;
painter->drawRect(option.rect.x(), option.rect.y(),
width, option.rect.height());
painter->drawText(option.rect, QString::fromStdString(std::to_string(size)));
painter->restore();
}
QSize SortDrawDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
int size = index.data().toInt();
int width = size;
return QSize(width, option.rect.height());
}
}