forked from openkylin/ukui-search
Merge branch 'ukss-dev-richtext' into 'ukss-dev'
处理富文本末尾超长省略问题 See merge request kylin-desktop/ukui-search!344
This commit is contained in:
commit
6a9ee98a84
|
@ -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("<pre>" + text + "</pre>");
|
||||
m_textDoc->setPlainText(text);
|
||||
m_hightLightEffectHelper->setDocument(m_textDoc);
|
||||
m_hightLightEffectHelper->rehighlight();
|
||||
m_textDoc->drawContents(painter);
|
||||
|
|
Loading…
Reference in New Issue