diff options
author | Jens Bache-Wiig <jbache@trolltech.com> | 2010-04-13 15:01:59 (GMT) |
---|---|---|
committer | Jens Bache-Wiig <jbache@trolltech.com> | 2010-04-13 15:04:25 (GMT) |
commit | e0be4d7a64677d8739e342880340ae2e9c25b5ee (patch) | |
tree | 36275639337a1919399224f351ab5a2d4cc366a9 /src/gui/widgets/qlineedit.cpp | |
parent | 9ef3b0687df14f738ac59d447a0cc438ef270744 (diff) | |
download | Qt-e0be4d7a64677d8739e342880340ae2e9c25b5ee.zip Qt-e0be4d7a64677d8739e342880340ae2e9c25b5ee.tar.gz Qt-e0be4d7a64677d8739e342880340ae2e9c25b5ee.tar.bz2 |
Fix margins for placeholdertext in QLineEdit
The margins were lacking the minimum font bearing
that normal text gets. This would generally make
the margin too small when showing this text.
Reviewed-by: ogoffart
Task-number: QTBUG-9823
Diffstat (limited to 'src/gui/widgets/qlineedit.cpp')
-rw-r--r-- | src/gui/widgets/qlineedit.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 0b8dca9..655fc61 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1869,13 +1869,18 @@ void QLineEdit::paintEvent(QPaintEvent *) } QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height()); + int minLB = qMax(0, -fm.minLeftBearing()); + int minRB = qMax(0, -fm.minRightBearing()); + if (d->control->text().isEmpty()) { if (!hasFocus() && !d->placeholderText.isEmpty()) { QColor col = pal.text().color(); col.setAlpha(128); QPen oldpen = p.pen(); p.setPen(col); - p.drawText(lineRect, va, d->placeholderText); + lineRect.adjust(minLB, 0, 0, 0); + QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width()); + p.drawText(lineRect, va, elidedText); p.setPen(oldpen); return; } @@ -1889,8 +1894,6 @@ void QLineEdit::paintEvent(QPaintEvent *) // the below code handles all scrolling based on the textline (widthUsed, // minLB, minRB), the line edit rect (lineRect) and the cursor position // (cix). - int minLB = qMax(0, -fm.minLeftBearing()); - int minRB = qMax(0, -fm.minRightBearing()); int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; if ((minLB + widthUsed) <= lineRect.width()) { // text fits in lineRect; use hscroll for alignment |