From: Gabriel de Dietrich Date: Tue, 9 Apr 2013 12:46:04 +0000 (+0200) Subject: TextInput: Fix cursor height X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=77dbda72b04eec6040a13791992af7a066383e6a;p=konrad%2Fqtdeclarative.git 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 --- 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); } /*!