QLineEdit: Fix cursor drawing issues

Entering Chinese in some fonts in an English environment causes
the cursor drawing coordinates to exceed the updated coordinates,
leaving behind stale pixels at the top.

Keep the refresh and draw area calculation methods the same when
rendering the contents in QLineEdit::paintEvent, and when
calculating the update area in
QLineEditPrivate::adjustedControlRect.

Fixes: QTBUG-85569
Pick-to: 5.15
Change-Id: I978cb56f24f961086b1271e56d07ad1ced16f8ff
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Lu YaNing 2020-07-20 11:32:55 +08:00 committed by Volker Hilsheimer
parent a7ebcbfc04
commit b9cd399dc9
2 changed files with 3 additions and 1 deletions

View File

@ -2031,6 +2031,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
}
// the y offset is there to keep the baseline constant in case we have script changes in the text.
// Needs to be kept in sync with QLineEditPrivate::adjustedControlRect
QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
// draw text, selections and cursors

View File

@ -70,12 +70,13 @@ QT_BEGIN_NAMESPACE
const int QLineEditPrivate::verticalMargin(1);
const int QLineEditPrivate::horizontalMargin(2);
// Needs to be kept in sync with QLineEdit::paintEvent
QRect QLineEditPrivate::adjustedControlRect(const QRect &rect) const
{
QRect widgetRect = !rect.isEmpty() ? rect : q_func()->rect();
QRect cr = adjustedContentsRect();
int cix = cr.x() - hscroll + horizontalMargin;
return widgetRect.translated(QPoint(cix, vscroll));
return widgetRect.translated(QPoint(cix, vscroll - control->ascent() + q_func()->fontMetrics().ascent()));
}
int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const