From 827d0c023222c58443bd825c6287949a2cc07de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 10 Sep 2015 14:02:52 +0200 Subject: QLineEdit: Don't include left and right minimum bearing when drawing text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tor Arne Vestbø Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/widgets/widgets/qlineedit.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/widgets') 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; -- cgit v1.2.3