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>
This commit is contained in:
parent
a0aad95f5a
commit
827d0c0232
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user