TextInput: Fix cursor height
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>
Tue, 9 Apr 2013 12:46:04 +0000 (14:46 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Apr 2013 13:20:48 +0000 (15:20 +0200)
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 <jpnurmi@digia.com>

src/quick/items/qquicktextinput.cpp

index 52f991b..0d0d0a1 100644 (file)
@@ -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);
 }
 
 /*!