вопрос
QSize QItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const{ QVariant value = index.data(Qt::SizeHintRole); if (value.isValid()) return qvariant_cast<QSize>(value); QRect decorationRect = rect(option, index, Qt::DecorationRole); QRect displayRect = rect(option, index, Qt::DisplayRole); QRect checkRect = rect(option, index, Qt::CheckStateRole); doLayout(option, &checkRect, &decorationRect, &displayRect, true); return (decorationRect|displayRect|checkRect).size();}
tmpRect.setHeight(outRect.height());
void LogDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ painter->setClipRegion(option.rect); QString dataStr(index.model()->data(index).toString()); QString tmpStr; int pos; QFont font; QRect tmpRect; QRect outRect(option.rect.topLeft(), option.rect.bottomLeft()); for(;ttt.contains("##");) { pos = dataStr.indexOf("##"); dataStr.remove(0, pos+2); tmpStr = dataStr.mid(1, (ttt.indexOf("##")-1)); if (dataStr.at(0) == 'I') { if (type == 1) continue; painter->setPen(Qt::red); } if (dataStr.at(0) == 'R') { if (type == 0) continue; if (type != 1) font.setStrikeOut(true); painter->setPen(Qt::blue); } painter->setFont(font); tmpRect = painter->boundingRect(outRect, Qt::AlignVCenter, tmpStr); painter->drawText(tmpRect, Qt::AlignVCenter, tmpStr); outRect = tmpRect; painter->drawLine(tmpRect.topLeft(),tmpRect.bottomRight()); //промежуток между частями - чистый font.setStrikeOut(false); painter->setPen(Qt::black); tmpRect = painter->boundingRect(option.rect, option.displayAlignment, " "); tmpRect.moveTo(outRect.topRight()); outRect = tmpRect; painter->drawLine(tmpRect.topLeft(),tmpRect.bottomRight()); }}
QSize LogDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const{ return QSize(option.rect.width(), option.rect.height());}
QSize LogDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const{ return QSize(1000,1000);}