diff options
author | Dan Cape <dcape@qnx.com> | 2015-08-12 10:34:43 -0400 |
---|---|---|
committer | Dan Cape <dcape@qnx.com> | 2016-02-23 14:38:59 +0000 |
commit | 57a1224eb3003468b2851635e3ad4dae760c14b8 (patch) | |
tree | 113cb693ad00e133d001759ae6cafae550c689ad /src/widgets/widgets/qlineedit.cpp | |
parent | 20af1ad7ef48e8f669e464fcea3151c7694fa90e (diff) |
PlaceHolderText doesn't appear in RTL
Since placeholderText was using the layoutDirection from the control,
it was always getting LTR since there was no text added yet to the
control. By calling the isRightToLeft function on the placeholderText,
we can determine if it is RTL or not and apply that when drawing the
placeholderText. A change was also made to use the proper elide mode
depending on if it is LTR or RTL.
Task-number: QTBUG-36499
Change-Id: Ic4c9cb9b41d9180185ed35492518152c1122839f
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/widgets/widgets/qlineedit.cpp')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 3cdd7dc0f0..e93ed11930 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1899,13 +1899,19 @@ void QLineEdit::paintEvent(QPaintEvent *) if (d->shouldShowPlaceholderText()) { if (!d->placeholderText.isEmpty()) { + const Qt::LayoutDirection layoutDir = d->placeholderText.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight; + const Qt::Alignment alignPhText = QStyle::visualAlignment(layoutDir, QFlag(d->alignment)); QColor col = pal.text().color(); col.setAlpha(128); QPen oldpen = p.pen(); p.setPen(col); - QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width()); - p.drawText(lineRect, va, elidedText); + Qt::LayoutDirection oldLayoutDir = p.layoutDirection(); + p.setLayoutDirection(layoutDir); + + const QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width()); + p.drawText(lineRect, alignPhText, elidedText); p.setPen(oldpen); + p.setLayoutDirection(oldLayoutDir); } } |