fix(frontend):the search result item is align left while the layout direction is right to left.

This commit is contained in:
JunjieBai 2024-06-12 16:09:29 +08:00 committed by iaom
parent fda53e91e3
commit 25baa9140e
1 changed files with 4 additions and 2 deletions

View File

@ -44,7 +44,8 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
{ {
QStyleOptionViewItem opt = option; QStyleOptionViewItem opt = option;
initStyleOption(&opt, index); initStyleOption(&opt, index);
opt.displayAlignment = Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter); opt.displayAlignment = QApplication::isLeftToRight() ?
Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter) : Qt::Alignment(Qt::AlignRight|Qt::AlignVCenter);
QString originalText = opt.text; QString originalText = opt.text;
opt.text = QString(); opt.text = QString();
@ -87,7 +88,8 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
m_hightLightEffectHelper->setDocument(m_textDoc); m_hightLightEffectHelper->setDocument(m_textDoc);
m_hightLightEffectHelper->rehighlight(); m_hightLightEffectHelper->rehighlight();
painter->translate(textRect.x(), textRect.y() + (textRect.height() - fontMetrics.height()) / 2 - m_textDoc->documentMargin()); int textRectX = QApplication::isLeftToRight() ? textRect.x() : textRect.width() - fontMetrics.horizontalAdvance(text) - m_textDoc->documentMargin();
painter->translate(textRectX, textRect.y() + (textRect.height() - fontMetrics.height()) / 2 - m_textDoc->documentMargin());
m_textDoc->drawContents(painter); m_textDoc->drawContents(painter);
painter->restore(); painter->restore();
} }