#include "customdelegate.h" CustomDelegate::CustomDelegate(QObject *parent): QItemDelegate(parent) { } void CustomDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { bool mergeCell = index.data(UserRole_MergeCell).toBool(); if (mergeCell && index.column() == 0) { QModelIndex nextColumnIndex = index.siblingAtColumn(index.column() + 1); if (!nextColumnIndex.isValid()) { QItemDelegate::paint(painter, option, index); return; } QRect mergedRect(option.rect.x(), option.rect.y(), option.rect.width() * 2, option.rect.height()); painter->save(); painter->setClipRect(mergedRect); drawBackground(painter, option, index); drawDisplay(painter, option, mergedRect, index.data(Qt::DisplayRole).toString()); painter->restore(); } else { QItemDelegate::paint(painter, option, index); } } QSize CustomDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { return QItemDelegate::sizeHint(option, index); }