From 39068888011eea2c10f55a04c747418a92e73aee Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Thu, 5 Sep 2024 16:16:16 -0400 Subject: [PATCH] Fix SearchBar Placeholder Alignment in RTL Align placeholder at leading position in line edit --- src/searchbar.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 020dec6..a004e1e 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -54,7 +54,14 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) : setAlignment(KiwixApp::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft); mp_typingTimer = new QTimer(this); mp_typingTimer->setSingleShot(true); - setPlaceholderText(gt("search")); + + /* Placeholder does not affect line edit alignment and is aligned to line + edit purely by text direction (LTR leading RTL ending). Thus, we need + directional mask to make it LTR at leading position. + https://stackoverflow.com/questions/66430215/english-and-arabic-mixed-string-not-ordered-correctly-qt + */ + const QString ltrConversionChar = QString{"\u200e"}; + setPlaceholderText(ltrConversionChar + gt("search")); setToolTip(gt("search")); m_completer.setCompletionMode(QCompleter::UnfilteredPopupCompletion); m_completer.setCaseSensitivity(Qt::CaseInsensitive);