From 561ab99ad65711b61c47df9bd78ea928de525a53 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 19 Dec 2012 17:12:58 +1000 Subject: [PATCH] Ensure the cursorRectangle is updated as the width of the text changes. Outside of when of a monospace font is used, if the text changes the visual position of the cursor will have most likely changed as well even when the cursor index hasn't. Task-number: QTBUG-28677 Change-Id: If8077772d8541a677d5875976e6cd9fc453731df Reviewed-by: Alan Alpert --- src/quick/items/qquicktextinput.cpp | 4 +++- .../quick/qquicktextinput/tst_qquicktextinput.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 9067589..b305ad1 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -3275,6 +3275,7 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo bool inputMethodAttributesChanged = m_textDirty || m_selDirty; #endif bool alignmentChanged = false; + bool textChanged = false; if (m_textDirty) { // do validation @@ -3309,6 +3310,7 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo } if (m_textDirty) { + textChanged = true; m_textDirty = false; #ifndef QT_NO_IM m_preeditDirty = false; @@ -3344,7 +3346,7 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo #endif emitUndoRedoChanged(); - if (!emitCursorPositionChanged() && alignmentChanged) + if (!emitCursorPositionChanged() && (alignmentChanged || textChanged)) q->updateCursorRectangle(); return true; diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 3b1c5eb..86a05c3 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -3087,6 +3087,14 @@ void tst_qquicktextinput::cursorRectangle() input.setHAlign(leftToRight ? QQuickTextInput::AlignRight : QQuickTextInput::AlignLeft); r = input.cursorRectangle(); QCOMPARE(r.left(), leftToRight ? input.width() : 0); + + QSignalSpy cursorRectangleSpy(&input, SIGNAL(cursorRectangleChanged())); + + QString widerText = shortText; + widerText[1] = 'W'; // Assumes shortText is at least two characters long. + input.setText(widerText); + + QCOMPARE(cursorRectangleSpy.count(), 1); } void tst_qquicktextinput::readOnly() -- 1.7.2.5