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

Merge pull request !20 from iaom/1010
This commit is contained in:
iaom 2022-10-26 09:07:00 +00:00 committed by Gitee
commit 9f54e92ee4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
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();
}