From 77dbda72b04eec6040a13791992af7a066383e6a Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 9 Apr 2013 14:46:04 +0200 Subject: [PATCH] TextInput: Fix cursor height On many platforms, the current cursor looks too tall. The logic used in this patch is inspired by what we have in QTextLayout::drawCursor(). It still looks too tall on Mac, but so it does in Qt Widgets. QQuickTextInput::positionToRectangle() has also been updated for consistency. Change-Id: I69b8ad246238d54db370db639a319a3edba6d78a Reviewed-by: J-P Nurmi --- src/quick/items/qquicktextinput.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 52f991b..0d0d0a1 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -777,7 +777,10 @@ QRectF QQuickTextInput::cursorRectangle() const QTextLine l = d->m_textLayout.lineForTextPosition(c); if (!l.isValid()) return QRectF(); - return QRectF(l.cursorToX(c) - d->hscroll, l.y() - d->vscroll, 1, l.height()); + qreal x = l.cursorToX(c) - d->hscroll; + qreal y = l.y() - d->vscroll; + qreal height = l.ascent() + l.descent(); + return QRectF(x, y, 1, height); } /*! @@ -1371,9 +1374,12 @@ QRectF QQuickTextInput::positionToRectangle(int pos) const pos += d->preeditAreaText().length(); #endif QTextLine l = d->m_textLayout.lineForTextPosition(pos); - return l.isValid() - ? QRectF(l.cursorToX(pos) - d->hscroll, l.y() - d->vscroll, 1, l.height()) - : QRectF(); + if (!l.isValid()) + return QRectF(); + qreal x = l.cursorToX(pos) - d->hscroll; + qreal y = l.y() - d->vscroll; + qreal height = l.ascent() + l.descent(); + return QRectF(x, y, 1, height); } /*! -- 2.7.4