summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLu YaNing <luyaning@uniontech.com>2020-07-20 11:32:55 +0800
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-23 15:05:04 +0200
commitb9cd399dc99487371a17dbdfc434b62dc8508c3f (patch)
tree1fd2a36806404f3ea8a755818a36dcaf50f59bbe /src
parenta7ebcbfc04e7396618247c321443c9437481d0df (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qlineedit.cpp1
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp3
2 files changed, 3 insertions, 1 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index d95c004c8c..13e3a070b9 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -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
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 6424c1452c..05b14b1007 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -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