From 074019bc899de7aae881afd83bea731b02a232ec Mon Sep 17 00:00:00 2001 From: hewenfei Date: Tue, 5 Jul 2022 10:26:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=AF=8C=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E8=B6=85=E9=95=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/view/result-view-delegate.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/view/result-view-delegate.cpp b/frontend/view/result-view-delegate.cpp index ce0cc25..3bc81b5 100644 --- a/frontend/view/result-view-delegate.cpp +++ b/frontend/view/result-view-delegate.cpp @@ -33,8 +33,11 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op QStyle *style = opt.widget->style(); style->proxy()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget); //绘制非文本区域内容 - opt.text = text; QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, opt.widget); + QFontMetrics fontMetrics(opt.font); + text = fontMetrics.elidedText(text, Qt::ElideRight, textRect.width() - 5); //富余5px的宽度 + opt.text = text; + painter->save(); if(opt.state & QStyle::State_Selected) { m_hightLightEffectHelper->setTextColor(QBrush(opt.palette.highlightedText().color())); @@ -43,7 +46,7 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op } painter->translate(textRect.topLeft()); - m_textDoc->setHtml("
" + text + "
"); + m_textDoc->setPlainText(text); m_hightLightEffectHelper->setDocument(m_textDoc); m_hightLightEffectHelper->rehighlight(); m_textDoc->drawContents(painter);