Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -106,10 +106,16 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
painter->fillRect(lineNumberAreaRect, QBrush(isSelected ?
option.palette.brush(cg, QPalette::Highlight) :
option.palette.color(cg, QPalette::Base).darker(111)));
painter->setPen(isSelected ?
option.palette.color(cg, QPalette::HighlightedText) : Qt::darkGray);
painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0),
Qt::AlignRight | Qt::AlignVCenter, QString::number(lineNumber));
QStyleOptionViewItemV3 opt = option;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment