41 lines
1.5 KiB
C++
41 lines
1.5 KiB
C++
#include "attributeTableDelegate.h"
|
||
#include <QPainter>
|
||
|
||
AttributeTableDelegate::AttributeTableDelegate(QTableView* view, QObject *parent)
|
||
: QStyledItemDelegate(parent)
|
||
, m_tableView(view)
|
||
{
|
||
}
|
||
|
||
AttributeTableDelegate::~AttributeTableDelegate()
|
||
{}
|
||
|
||
void AttributeTableDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||
{
|
||
if(index.column() == 0)
|
||
{
|
||
QString text = index.data(Qt::DisplayRole).toString();
|
||
if(text.contains("-") && m_tableView && m_tableView->model()) //删除项,整行画一条红线
|
||
{
|
||
int row = index.row();
|
||
for(int col = 0; col < m_tableView->model()->columnCount(); col++)
|
||
{
|
||
QModelIndex index = m_tableView->model()->index(row, col);
|
||
QRect rect = m_tableView->visualRect(index);
|
||
painter->save();
|
||
painter->setPen(Qt::red);
|
||
painter->drawLine(rect.x(), rect.y() + rect.height()*0.5, rect.x() + rect.width(), rect.y() + rect.height()*0.5); //painter属于view,所以要以view的坐标系为标准
|
||
painter->restore();
|
||
QStyledItemDelegate::paint(painter, option, index);
|
||
}
|
||
}
|
||
}
|
||
else if (index.data(Qt::UserRole + 1).toBool())
|
||
{
|
||
QStyleOptionViewItem opt = option;
|
||
initStyleOption(&opt, index);
|
||
opt.font.setBold(true);
|
||
QStyledItemDelegate::paint(painter, opt, index);
|
||
}
|
||
}
|