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);