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>
bb10
Dan Cape 2015-08-12 10:34:43 -04:00
parent 20af1ad7ef
commit 57a1224eb3
1 changed files with 8 additions and 2 deletions

View File

@ -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);
}
}