ui: Set QStyleOptionViewItem::HasDisplay in SearchItemDelegate

This fixes the bug with item's text not rendered, when certain styles
were in use, e.g. KDE's Breeze.

Fixes #540.
This commit is contained in:
Oleg Shparber
2016-08-02 23:24:26 -04:00
parent cb28be436c
commit 1a06b22f04
2 changed files with 9 additions and 5 deletions
+8 -4
View File
@@ -108,13 +108,17 @@ void SearchItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
}
}
// This should not happen unless a docset is corrupted.
if (index.data().isNull())
return;
// Match QCommonStyle behaviour.
const QString text = index.data().toString();
opt.features |= QStyleOptionViewItem::HasDisplay;
opt.text = index.data().toString();
const QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, opt.widget)
.adjusted(margin, 0, -margin, 0);
const QFontMetrics &fm = opt.fontMetrics;
const QString elidedText = fm.elidedText(text, opt.textElideMode, textRect.width());
const QString elidedText = fm.elidedText(opt.text, opt.textElideMode, textRect.width());
if (!m_highlight.isEmpty()) {
painter->save();
@@ -125,7 +129,7 @@ void SearchItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
? QColor::fromRgb(255, 255, 100, 20) : QColor::fromRgb(255, 255, 100, 120);
for (int i = 0;;) {
const int matchIndex = text.indexOf(m_highlight, i, Qt::CaseInsensitive);
const int matchIndex = opt.text.indexOf(m_highlight, i, Qt::CaseInsensitive);
if (matchIndex == -1 || matchIndex >= elidedText.length() - 1)
break;
+1 -1
View File
@@ -39,7 +39,7 @@ public:
const QModelIndex &index) override;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
public slots:
void setHighlight(const QString &text);