-
Notifications
You must be signed in to change notification settings - Fork 19
/
styleditemdelegate.cpp
27 lines (22 loc) · 966 Bytes
/
styleditemdelegate.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
#include "styleditemdelegate.h"
#include "tableview.h"
#include <QDebug>
StyledItemDelegate::StyledItemDelegate()
: QStyledItemDelegate ()
{
}
void StyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem opt(option);
opt.state &= ~QStyle::State_HasFocus;
TableView *view = qobject_cast<TableView *>(opt.styleObject);
QTableView::SelectionBehavior behavior = view->selectionBehavior();
QModelIndex hoverIndex = view->hoverIndex();
if (!(option.state & QStyle::State_Selected) && behavior != QTableView::SelectItems) {
if (behavior == QTableView::SelectRows && hoverIndex.row() == index.row())
opt.state |= QStyle::State_MouseOver;
if (behavior == QTableView::SelectColumns && hoverIndex.column() == index.column())
opt.state |= QStyle::State_MouseOver;
}
QStyledItemDelegate::paint(painter, opt, index);
}