diff --git a/src/plugins/find/gui/searchresultitemdelegate.cpp b/src/plugins/find/gui/searchresultitemdelegate.cpp index e53a0708b..8cd5439fc 100644 --- a/src/plugins/find/gui/searchresultitemdelegate.cpp +++ b/src/plugins/find/gui/searchresultitemdelegate.cpp @@ -402,10 +402,6 @@ void SearchResultItemDelegate::drawDisplay(QPainter *painter, const QStyleOption painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text)); } - QString displayText = text.trimmed(); - if (displayText.isEmpty()) - return; - const QStyleOptionViewItem opt = option; const QWidget *widget = option.widget; @@ -419,8 +415,20 @@ void SearchResultItemDelegate::drawDisplay(QPainter *painter, const QStyleOption QTextLayout textLayout; textLayout.setTextOption(textOption); textLayout.setFont(option.font); + + // Remove leading spaces + QString displayText = text.trimmed(); + int leftSpaces = text.indexOf(displayText); textLayout.setText(displayText); - textLayout.setFormats(formatList.toVector()); + + // Adjust offsets in formatList + QList adjustedFormats = formatList; + if (leftSpaces != 0) { + for (auto &format : adjustedFormats) { + format.start -= leftSpaces; + } + } + textLayout.setFormats(adjustedFormats.toVector()); QSizeF textLayoutSize = doTextLayout(&textLayout, textRect.width()); if (textRect.width() < textLayoutSize.width()) {