From bfcefe4ce106ae561081f14ca290bbff46438b36 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Wed, 12 Jun 2024 16:09:29 +0800 Subject: [PATCH] fix(frontend):the search result item is align left while the layout direction is right to left. --- frontend/view/result-view-delegate.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/view/result-view-delegate.cpp b/frontend/view/result-view-delegate.cpp index dd4f7b5..bc10915 100644 --- a/frontend/view/result-view-delegate.cpp +++ b/frontend/view/result-view-delegate.cpp @@ -44,7 +44,8 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op { QStyleOptionViewItem opt = option; 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; opt.text = QString(); @@ -87,7 +88,8 @@ void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op m_hightLightEffectHelper->setDocument(m_textDoc); 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); painter->restore(); }