update highlineview lastorder
This commit is contained in:
@@ -69,4 +69,47 @@ QString NumberFormatDelegate::displayText(const QVariant &value, const QLocale &
|
||||
}
|
||||
|
||||
return QStyledItemDelegate::displayText(value, locale);
|
||||
}
|
||||
|
||||
|
||||
HighlightDelegate::HighlightDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void HighlightDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QStyleOptionViewItem opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
|
||||
// 检查是否需要高亮 - 通过映射到源模型获取高亮状态
|
||||
QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model());
|
||||
QSortFilterProxyModel *proxyModel = qobject_cast<QSortFilterProxyModel*>(model);
|
||||
|
||||
bool isHighlighted = false;
|
||||
if (proxyModel) {
|
||||
QModelIndex sourceIndex = proxyModel->mapToSource(index);
|
||||
isHighlighted = sourceIndex.data(IsHighlightedRole).toBool();
|
||||
}
|
||||
else {
|
||||
isHighlighted = index.data(IsHighlightedRole).toBool();
|
||||
}
|
||||
|
||||
if (isHighlighted) {
|
||||
// 设置高亮背景
|
||||
painter->fillRect(opt.rect, QColor(255, 192, 203)); // 浅黄色背景
|
||||
// 设置加粗字体
|
||||
QFont boldFont = opt.font;
|
||||
boldFont.setBold(true);
|
||||
painter->setFont(boldFont);
|
||||
|
||||
// 绘制文本
|
||||
painter->setPen(opt.palette.color(QPalette::Text));
|
||||
painter->drawText(opt.rect, opt.displayAlignment, opt.text);
|
||||
}
|
||||
else {
|
||||
// 正常绘制
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user