修复结果列表文字显示不居中的问题.

This commit is contained in:
iaom 2022-10-26 15:12:09 +08:00
parent 1832b01721
commit 4e0243a44d
1 changed files with 5 additions and 3 deletions

View File

@ -17,7 +17,7 @@ void ResultViewDelegate::setSearchKeyword(const QString &regFindKeyWords)
QSize ResultViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size = QStyledItemDelegate::sizeHint(option,index);
size.setHeight(size.height() + 10);
size.setHeight(size.height() + 50);
return size;
}
@ -35,7 +35,7 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, opt.widget);
QFontMetrics fontMetrics(opt.font);
text = fontMetrics.elidedText(text, Qt::ElideRight, textRect.width() - 5); //富余5px的宽度
text = fontMetrics.elidedText(text, Qt::ElideRight, textRect.width() - m_textDoc->documentMargin() - 1); //富余5px的宽度
opt.text = text;
painter->save();
@ -44,11 +44,13 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
} else {
m_hightLightEffectHelper->setTextColor(QBrush(opt.palette.text().color()));
}
painter->translate(textRect.topLeft());
m_textDoc->setPlainText(text);
m_hightLightEffectHelper->setDocument(m_textDoc);
m_hightLightEffectHelper->rehighlight();
painter->translate(textRect.x(), textRect.y() + (textRect.height() - fontMetrics.height()) / 2 - m_textDoc->documentMargin());
m_textDoc->drawContents(painter);
painter->restore();
}