Commit 3bc20dbb authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Fixed vertical alignment of line numbers in search results on Mac

Due to different text positioning logic between the QItemDelegate and
the way SearchResultTreeItemDelegate drew the line numbers, the line
numbers did not align properly to the line of text next to it.

This was fixed by relying on QItemDelegate::drawDisplay for drawing the
line numbers, so that the same positioning logic is used.

This exposed a small right-alignment bug in QTextLayout, for which a fix
is coming to Qt.

Done-with: Erik Verbruggen
parent a49bbb4d
...@@ -106,10 +106,16 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle ...@@ -106,10 +106,16 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
painter->fillRect(lineNumberAreaRect, QBrush(isSelected ? painter->fillRect(lineNumberAreaRect, QBrush(isSelected ?
option.palette.brush(cg, QPalette::Highlight) : option.palette.brush(cg, QPalette::Highlight) :
option.palette.color(cg, QPalette::Base).darker(111))); option.palette.color(cg, QPalette::Base).darker(111)));
painter->setPen(isSelected ?
option.palette.color(cg, QPalette::HighlightedText) : Qt::darkGray); QStyleOptionViewItemV3 opt = option;
painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0), opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
Qt::AlignRight | Qt::AlignVCenter, QString::number(lineNumber)); opt.palette.setColor(cg, QPalette::Text, Qt::darkGray);
const QStyle *style = QApplication::style();
const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
const QRect rowRect = lineNumberAreaRect.adjusted(-textMargin, 0, textMargin-lineNumberAreaHorizontalPadding, 0);
QItemDelegate::drawDisplay(painter, opt, rowRect, QString::number(lineNumber));
return lineNumberAreaWidth; return lineNumberAreaWidth;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment