From 57a1224eb3003468b2851635e3ad4dae760c14b8 Mon Sep 17 00:00:00 2001 From: Dan Cape Date: Wed, 12 Aug 2015 10:34:43 -0400 Subject: 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 --- src/widgets/widgets/qlineedit.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/widgets/widgets/qlineedit.cpp') 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); } } -- cgit v1.2.3