diff options
author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-04-09 14:46:04 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-16 15:20:48 +0200 |
commit | 77dbda72b04eec6040a13791992af7a066383e6a (patch) | |
tree | d124f15320ef0f0438ef4f74835081d88c5d236a /src/quick/items/qquicktextinput.cpp | |
parent | f012ddd23226808a459104d14654e9e25f749cb7 (diff) |
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 <jpnurmi@digia.com>
Diffstat (limited to 'src/quick/items/qquicktextinput.cpp')
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 52f991b475..0d0d0a17e0 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); } /*! |