diff options
author | Zhang Hao <zhanghao@uniontech.com> | 2021-07-23 15:39:57 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-23 12:39:59 +0000 |
commit | 09cae81bf7e0bcd8c1cfbeb38d0db7b363f2f165 (patch) | |
tree | be60a0dbc707422a7afb4976f687aa3b97d9c9f8 | |
parent | 6fc081a8d4835279fd75f8748f7ab29319da63f3 (diff) |
QLineEdit: account for the placeholderText when computing lineRect
If in a QLineEdit the placeholderText uses e.g. Tibetan language, then the
height of font as reported by QFontMetrics might be less than the height
of the boundingRect calculated for the placeholderText. This can cause the
placeholderText to display incompletely.
Fix this by using QFontMetrics::boundingRect instead of QFontMetrics::height
when computing lineRect.
Fixes: QTBUG-95341
Change-Id: I9eef35fd89c5c1d79f6dd703355634d6905ca967
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit d2670601890a188e2d083460b6e65f9df1e8f6fe)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 958b784c50..9a65bc3eae 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1979,21 +1979,28 @@ void QLineEdit::paintEvent(QPaintEvent *) p.setClipRect(r); QFontMetrics fm = fontMetrics(); + int fmHeight = 0; + if (d->shouldShowPlaceholderText()) + fmHeight = fm.boundingRect(d->placeholderText).height(); + else + fmHeight = fm.boundingRect(d->control->text() + d->control->preeditAreaText()).height(); + fmHeight = qMax(fmHeight, fm.height()); + Qt::Alignment va = QStyle::visualAlignment(d->control->layoutDirection(), QFlag(d->alignment)); switch (va & Qt::AlignVertical_Mask) { case Qt::AlignBottom: - d->vscroll = r.y() + r.height() - fm.height() - QLineEditPrivate::verticalMargin; + d->vscroll = r.y() + r.height() - fmHeight - QLineEditPrivate::verticalMargin; break; case Qt::AlignTop: d->vscroll = r.y() + QLineEditPrivate::verticalMargin; break; default: //center - d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2; + d->vscroll = r.y() + (r.height() - fmHeight + 1) / 2; break; } QRect lineRect(r.x() + QLineEditPrivate::horizontalMargin, d->vscroll, - r.width() - 2 * QLineEditPrivate::horizontalMargin, fm.height()); + r.width() - 2 * QLineEditPrivate::horizontalMargin, fmHeight); if (d->shouldShowPlaceholderText()) { if (!d->placeholderText.isEmpty()) { |