Skip to content

Commit

Permalink
fix: [search] The background color position is incorrect
Browse files Browse the repository at this point in the history
as title

Log: fix issue
  • Loading branch information
Kakueeen committed Dec 3, 2024
1 parent 2091f3a commit 34203b0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/plugins/find/gui/searchresultitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<QTextLayout::FormatRange> 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()) {
Expand Down

0 comments on commit 34203b0

Please sign in to comment.