-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprojectitemdelegate.cpp
33 lines (30 loc) · 1.05 KB
/
projectitemdelegate.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
#include "projectitemdelegate.h"
#include <QPainter>
#include <QBrush>
#include <QTextItem>
ProjectItemDelegate::ProjectItemDelegate(QObject *parent) :
QAbstractItemDelegate(parent)
{
}
void ProjectItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
// int adjust = -5;
// QRect itemRect = option.rect;
// itemRect.adjust(adjust, adjust, adjust, adjust);
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
painter->setBrush(QBrush(Qt::white));
painter->setPen(Qt::white);
}
else {
painter->setBrush(QBrush(Qt::black));
}
QString projectName = qvariant_cast<QString>(index.data(nameTextRole));
painter->drawText(option.rect.adjusted(5, 5, 5, 5), projectName);
painter->restore();
}
QSize ProjectItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QSize(option.rect.width(), 30);
}