diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-09-10 14:02:52 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-09-22 00:05:53 +0000 |
commit | 827d0c023222c58443bd825c6287949a2cc07de7 (patch) | |
tree | 95fcc97a4dfa02f102bd4bf37b08f6044e36d220 /src/widgets | |
parent | a0aad95f5ad1ff044f5e46cf2d3302c42d058f6a (diff) |
QLineEdit: Don't include left and right minimum bearing when drawing text
The naturalTextWidth() of the QTextLayout already includes the left
and right bearing of the actual text in the line edit, there's no need
to shift the text based on the minimum left and right bearings as well.
This may result in text that is closer to the edges of the line edit
on platforms that relied on this flawed logic, but that should be
adjusted back using the corresponding style hints.
Change-Id: I1d5edbeda7afe3e69b972841d280eb9e573675f5
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 0500907b3d..32502fca09 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1897,18 +1897,14 @@ 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->shouldShowPlaceholderText()) { if (!d->placeholderText.isEmpty()) { QColor col = pal.text().color(); col.setAlpha(128); QPen oldpen = p.pen(); p.setPen(col); - QRect ph = lineRect.adjusted(minLB, 0, 0, 0); - QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, ph.width()); - p.drawText(ph, va, elidedText); + QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width()); + p.drawText(lineRect, va, elidedText); p.setPen(oldpen); } } @@ -1918,11 +1914,10 @@ void QLineEdit::paintEvent(QPaintEvent *) // horizontal scrolling. d->hscroll is the left indent from the beginning // of the text line to the left edge of lineRect. we update this value // depending on the delta from the last paint event; in effect this means - // the below code handles all scrolling based on the textline (widthUsed, - // minLB, minRB), the line edit rect (lineRect) and the cursor position - // (cix). - int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; - if ((minLB + widthUsed) <= lineRect.width()) { + // the below code handles all scrolling based on the textline (widthUsed), + // the line edit rect (lineRect) and the cursor position (cix). + int widthUsed = qRound(d->control->naturalTextWidth()) + 1; + if (widthUsed <= lineRect.width()) { // text fits in lineRect; use hscroll for alignment switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) { case Qt::AlignRight: @@ -1936,7 +1931,6 @@ void QLineEdit::paintEvent(QPaintEvent *) d->hscroll = 0; break; } - d->hscroll -= minLB; } else if (cix - d->hscroll >= lineRect.width()) { // text doesn't fit, cursor is to the right of lineRect (scroll right) d->hscroll = cix - lineRect.width() + 1; |