Ensure the cursor delegate position is correct when wrapping.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Wed, 18 Apr 2012 07:20:24 +0000 (17:20 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 19 Apr 2012 04:16:28 +0000 (06:16 +0200)
When inserting text into a TextEdit with implicit width and wrapping
the cursor delegate position has to be updated after the width is
expanded to the implicit width otherwise it will be positioned in a
wrapped location.

Change-Id: Ibcb709ec1b4f6827ea8ae919f2e0c932c7372869
Reviewed-by: Martin Jones <martin.jones@nokia.com>
12 files changed:
src/quick/items/qquicktextcontrol.cpp
src/quick/items/qquicktextcontrol_p.h
src/quick/items/qquicktextcontrol_p_p.h
src/quick/items/qquicktextedit.cpp
tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml
tests/auto/quick/qquicktextedit/data/cursorTestInline.qml
tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml
tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml
tests/auto/quick/qquicktextinput/data/cursorTestInline.qml
tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml
tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp

index f63e6a7..7fa990b 100644 (file)
@@ -110,7 +110,8 @@ QQuickTextControlPrivate::QQuickTextControlPrivate()
       isEnabled(true),
       hadSelectionOnMousePress(false),
       wordSelectionEnabled(false),
-      hasImState(false)
+      hasImState(false),
+      cursorRectangleChanged(false)
 {}
 
 bool QQuickTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e)
@@ -253,7 +254,7 @@ bool QQuickTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e)
     if (moved) {
         if (cursor.position() != oldCursorPos)
             emit q->cursorPositionChanged();
-        emit q->cursorRectangleChanged();
+        q->updateCursorRectangle(true);
     } else if (isNavigationEvent && oldSelection.anchor() == cursor.anchor()) {
         return false;
     }
@@ -275,7 +276,7 @@ void QQuickTextControlPrivate::updateCurrentCharFormat()
     lastCharFormat = fmt;
 
     emit q->currentCharFormatChanged(fmt);
-    emit q->cursorRectangleChanged();
+    cursorRectangleChanged = true;
 }
 
 void QQuickTextControlPrivate::init(Qt::TextFormat format, const QString &text, QTextDocument *document)
@@ -366,7 +367,7 @@ void QQuickTextControlPrivate::setContent(Qt::TextFormat format, const QString &
     if (!document)
         doc->setModified(false);
 
-    emit q->cursorRectangleChanged();
+    q->updateCursorRectangle(true);
     emit q->cursorPositionChanged();
 }
 
@@ -443,7 +444,7 @@ void QQuickTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged /
             qGuiApp->inputMethod()->update(Qt::ImCurrentSelection);
         emit q->selectionChanged();
     }
-    emit q->cursorRectangleChanged();
+    q->updateCursorRectangle(true);
 }
 
 void QQuickTextControlPrivate::_q_updateCurrentCharFormatAndSelection()
@@ -469,7 +470,7 @@ void QQuickTextControlPrivate::_q_emitCursorPosChanged(const QTextCursor &someCu
     Q_Q(QQuickTextControl);
     if (someCursor.isCopyOf(cursor)) {
         emit q->cursorPositionChanged();
-        emit q->cursorRectangleChanged();
+        cursorRectangleChanged = true;
     }
 }
 
@@ -592,7 +593,7 @@ void QQuickTextControl::undo()
     d->doc->undo(&d->cursor);
     if (d->cursor.position() != oldCursorPos)
         emit cursorPositionChanged();
-    emit cursorRectangleChanged();
+    updateCursorRectangle(true);
 }
 
 void QQuickTextControl::redo()
@@ -601,9 +602,9 @@ void QQuickTextControl::redo()
     d->repaintSelection();
     const int oldCursorPos = d->cursor.position();
     d->doc->redo(&d->cursor);
-        if (d->cursor.position() != oldCursorPos)
+    if (d->cursor.position() != oldCursorPos)
         emit cursorPositionChanged();
-    emit cursorRectangleChanged();
+    updateCursorRectangle(true);
 }
 
 QQuickTextControl::QQuickTextControl(QTextDocument *doc, QObject *parent)
@@ -623,6 +624,15 @@ QTextDocument *QQuickTextControl::document() const
     return d->doc;
 }
 
+void QQuickTextControl::updateCursorRectangle(bool force)
+{
+    Q_D(QQuickTextControl);
+    const bool update = d->cursorRectangleChanged || force;
+    d->cursorRectangleChanged = false;
+    if (update)
+        emit cursorRectangleChanged();
+}
+
 void QQuickTextControl::setTextCursor(const QTextCursor &cursor)
 {
     Q_D(QQuickTextControl);
@@ -633,7 +643,7 @@ void QQuickTextControl::setTextCursor(const QTextCursor &cursor)
     d->cursor = cursor;
     d->cursorOn = d->hasFocus && (d->interactionFlags & Qt::TextEditable);
     d->_q_updateCurrentCharFormatAndSelection();
-    emit cursorRectangleChanged();
+    updateCursorRectangle(true);
     d->repaintOldAndNewSelection(oldSelection);
     if (posChanged)
         emit cursorPositionChanged();
@@ -956,8 +966,7 @@ process:
     e->accept();
     cursorOn = true;
 
-    emit q->cursorRectangleChanged();
-
+    q->updateCursorRectangle(true);
     updateCurrentCharFormat();
 }
 
@@ -1198,14 +1207,14 @@ void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &po
     }
 
     if (interactionFlags & Qt::TextEditable) {
-        emit q->cursorRectangleChanged();
+        q->updateCursorRectangle(true);
         if (cursor.position() != oldCursorPos)
             emit q->cursorPositionChanged();
         _q_updateCurrentCharFormatAndSelection();
     } else {
         if (cursor.position() != oldCursorPos) {
             emit q->cursorPositionChanged();
-            emit q->cursorRectangleChanged();
+            q->updateCursorRectangle(true);
         }
         selectionChanged();
     }
@@ -1316,7 +1325,7 @@ void QQuickTextControlPrivate::mouseReleaseEvent(QMouseEvent *e, const QPointF &
 
     if (cursor.position() != oldCursorPos) {
         emit q->cursorPositionChanged();
-        emit q->cursorRectangleChanged();
+        q->updateCursorRectangle(true);
     }
 
     if (interactionFlags & Qt::LinksAccessibleByMouse) {
@@ -1435,7 +1444,6 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
             int blockStart = a.start + cursor.block().position();
             cursor.setPosition(blockStart, QTextCursor::MoveAnchor);
             cursor.setPosition(blockStart + a.length, QTextCursor::KeepAnchor);
-            emit q->cursorRectangleChanged();
             repaintOldAndNewSelection(oldCursor);
             forceSelectionChanged = true;
         }
@@ -1475,8 +1483,7 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
     QTextCursorPrivate *cursor_d = QTextCursorPrivate::getPrivate(&cursor);
     if (cursor_d)
         cursor_d->setX();
-    if (oldPreeditCursor != preeditCursor)
-        emit q->cursorRectangleChanged();
+    q->updateCursorRectangle(oldPreeditCursor != preeditCursor || forceSelectionChanged);
     selectionChanged(forceSelectionChanged);
 }
 
@@ -1609,7 +1616,7 @@ void QQuickTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::M
     const QTextCursor oldSelection = d->cursor;
     const bool moved = d->cursor.movePosition(op, mode);
     d->_q_updateCurrentCharFormatAndSelection();
-    emit cursorRectangleChanged();
+    updateCursorRectangle(true);
     d->repaintOldAndNewSelection(oldSelection);
     if (moved)
         emit cursorPositionChanged();
@@ -1690,7 +1697,7 @@ void QQuickTextControl::insertFromMimeData(const QMimeData *source)
 
     if (hasData)
         d->cursor.insertFragment(fragment);
-    emit cursorRectangleChanged();
+    updateCursorRectangle(true);
 }
 
 void QQuickTextControlPrivate::activateLinkUnderCursor(QString href)
index aae9e12..57c26a1 100644 (file)
@@ -119,6 +119,8 @@ public:
     void setCursorIsFocusIndicator(bool b);
     void setWordSelectionEnabled(bool enabled);
 
+    void updateCursorRectangle(bool force);
+
     virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
     virtual QRectF blockBoundingRect(const QTextBlock &block) const;
 
index 3a10f00..f39bf67 100644 (file)
@@ -162,6 +162,7 @@ public:
     bool hadSelectionOnMousePress : 1;
     bool wordSelectionEnabled : 1;
     bool hasImState : 1;
+    bool cursorRectangleChanged : 1;
 
     void _q_copyLink();
     void _q_updateBlock(const QTextBlock &);
index f727c54..6fefab4 100644 (file)
@@ -897,6 +897,7 @@ void QQuickTextEdit::setCursorPosition(int pos)
         return;
     cursor.setPosition(pos);
     d->control->setTextCursor(cursor);
+    d->control->updateCursorRectangle(true);
 }
 
 /*!
@@ -1143,9 +1144,12 @@ void QQuickTextEdit::geometryChanged(const QRectF &newGeometry,
                                   const QRectF &oldGeometry)
 {
     Q_D(QQuickTextEdit);
-    if (newGeometry.width() != oldGeometry.width() && d->wrapMode != NoWrap && !d->inLayout)
+    if (newGeometry.width() != oldGeometry.width() && d->wrapMode != NoWrap && !d->inLayout) {
         updateSize();
+        moveCursorDelegate();
+    }
     QQuickImplicitSizeItem::geometryChanged(newGeometry, oldGeometry);
+
 }
 
 /*!
@@ -2169,6 +2173,7 @@ void QQuickTextEdit::insert(int position, const QString &text)
     } else {
         cursor.insertText(text);
     }
+    d->control->updateCursorRectangle(false);
 }
 
 /*!
@@ -2186,6 +2191,7 @@ void QQuickTextEdit::remove(int start, int end)
     cursor.setPosition(start, QTextCursor::MoveAnchor);
     cursor.setPosition(end, QTextCursor::KeepAnchor);
     cursor.removeSelectedText();
+    d->control->updateCursorRectangle(false);
 }
 
 QT_END_NAMESPACE
index 7e916ec..8eed022 100644 (file)
@@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white"
         text: "Hello world!"
         id: textEditObject;
         objectName: "textEditObject"
+        wrapMode: TextEdit.WordWrap
         cursorDelegate: Cursor {
             id:cursorInstance;
             objectName: "cursorInstance";
index 786f391..bda1710 100644 (file)
@@ -5,6 +5,7 @@ Rectangle { width: 300; height: 300; color: "white"
     TextEdit {
         text: "Hello world!"
         id: textEditObject
+        wrapMode: TextEdit.Wrap
         objectName: "textEditObject"
         cursorDelegate: Item {
             id:cursorInstance
index e3f629c..ab47368 100644 (file)
@@ -2,4 +2,8 @@ import QtQuick 2.0
 
 TextEdit {
     focus: true
+
+    cursorDelegate: Item {
+        objectName: "cursor"
+    }
 }
index 7113141..f218f64 100644 (file)
@@ -1944,10 +1944,6 @@ void tst_qquicktextedit::cursorDelegate()
         QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
         QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
     }
-    // Clear preedit text;
-    QInputMethodEvent event;
-    QGuiApplication::sendEvent(&view, &event);
-
 
     // Test delegate gets moved on mouse press.
     textEditObject->setSelectByMouse(true);
@@ -1992,6 +1988,25 @@ void tst_qquicktextedit::cursorDelegate()
     textEditObject->setCursorPosition(0);
     QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
     QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
+
+    // Delegate moved when text is entered
+    textEditObject->setText(QString());
+    for (int i = 0; i < 20; ++i) {
+        QTest::keyClick(&view, Qt::Key_A);
+        QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
+    }
+
+    // Delegate moved when text is entered by im.
+    textEditObject->setText(QString());
+    for (int i = 0; i < 20; ++i) {
+        QInputMethodEvent event;
+        event.setCommitString("a");
+        QGuiApplication::sendEvent(&view, &event);
+        QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y());
+    }
+
     //Test Delegate gets deleted
     textEditObject->setCursorDelegate(0);
     QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance"));
@@ -2645,14 +2660,17 @@ void tst_qquicktextedit::preeditCursorRectangle()
     QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(view.rootObject());
     QVERIFY(edit);
 
+    QQuickItem *cursor = edit->findChild<QQuickItem *>("cursor");
+    QVERIFY(cursor);
+
     QSignalSpy editSpy(edit, SIGNAL(cursorRectangleChanged()));
     QSignalSpy panelSpy(qGuiApp->inputMethod(), SIGNAL(cursorRectangleChanged()));
 
-    QRect currentRect;
+    QRectF currentRect;
 
     QInputMethodQueryEvent query(Qt::ImCursorRectangle);
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-    QRect previousRect = query.value(Qt::ImCursorRectangle).toRect();
+    QRectF previousRect = query.value(Qt::ImCursorRectangle).toRectF();
 
     // Verify that the micro focus rect is positioned the same for position 0 as
     // it would be if there was no preedit text.
@@ -2660,10 +2678,12 @@ void tst_qquicktextedit::preeditCursorRectangle()
             << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, preeditText.length(), QVariant()));
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent);
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-    currentRect = query.value(Qt::ImCursorRectangle).toRect();
+    currentRect = query.value(Qt::ImCursorRectangle).toRectF();
+    QCOMPARE(edit->cursorRectangle(), currentRect);
+    QCOMPARE(cursor->pos(), currentRect.topLeft());
     QCOMPARE(currentRect, previousRect);
-    QCOMPARE(editSpy.count(), 0);
-    QCOMPARE(panelSpy.count(), 0);
+    QCOMPARE(editSpy.count(), 0); editSpy.clear();
+    QCOMPARE(panelSpy.count(), 0); panelSpy.clear();
 
     // Verify that the micro focus rect moves to the left as the cursor position
     // is incremented.
@@ -2672,10 +2692,12 @@ void tst_qquicktextedit::preeditCursorRectangle()
                 << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, preeditText.length(), QVariant()));
         QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent);
         QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-        currentRect = query.value(Qt::ImCursorRectangle).toRect();
+        currentRect = query.value(Qt::ImCursorRectangle).toRectF();
+        QCOMPARE(edit->cursorRectangle(), currentRect);
+        QCOMPARE(cursor->pos(), currentRect.topLeft());
         QVERIFY(previousRect.left() < currentRect.left());
-        QVERIFY(editSpy.count() > 0); editSpy.clear();
-        QVERIFY(panelSpy.count() > 0); panelSpy.clear();
+        QCOMPARE(editSpy.count(), 1); editSpy.clear();
+        QCOMPARE(panelSpy.count(), 1); panelSpy.clear();
         previousRect = currentRect;
     }
 
@@ -2687,10 +2709,12 @@ void tst_qquicktextedit::preeditCursorRectangle()
     {   QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>());
         QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); }
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-    currentRect = query.value(Qt::ImCursorRectangle).toRect();
+    currentRect = query.value(Qt::ImCursorRectangle).toRectF();
+    QCOMPARE(edit->cursorRectangle(), currentRect);
+    QCOMPARE(cursor->pos(), currentRect.topLeft());
     QCOMPARE(currentRect, previousRect);
-    QVERIFY(editSpy.count() > 0);
-    QVERIFY(panelSpy.count() > 0);
+    QCOMPARE(editSpy.count(), 1);
+    QCOMPARE(panelSpy.count(), 1);
 }
 
 void tst_qquicktextedit::inputMethodComposing()
index 9277dcc..2f43449 100644 (file)
@@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white"
         text: "Hello world!"
         id: textInputObject;
         objectName: "textInputObject"
+        wrapMode: TextInput.Wrap
         cursorDelegate: Cursor {
             id:cursorInstance;
             objectName: "cursorInstance";
index efc4b19..e51a2f3 100644 (file)
@@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white"
         text: "Hello world!"
         id: textInputObject
         objectName: "textInputObject"
+        wrapMode: TextInput.WordWrap
         cursorDelegate: Item {
             id:cursorInstance
             objectName: "cursorInstance"
index 7aefdf2..907ea68 100644 (file)
@@ -3,4 +3,6 @@ import QtQuick 2.0
 TextInput {
     focus: true
     autoScroll: false
+
+    cursorDelegate: Item { objectName: "cursor" }
 }
index 4f2f3cb..925e4f9 100644 (file)
@@ -2359,6 +2359,70 @@ void tst_qquicktextinput::cursorDelegate()
     textInputObject->setCursorPosition(0);
     QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
     QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+
+
+    // Test delegate gets moved on mouse press.
+    textInputObject->setSelectByMouse(true);
+    textInputObject->setCursorPosition(0);
+    const QPoint point1 = textInputObject->positionToRectangle(5).center().toPoint();
+    QTest::qWait(400);  //ensure this isn't treated as a double-click
+    QTest::mouseClick(&view, Qt::LeftButton, 0, point1);
+    QTest::qWait(50);
+    QTRY_VERIFY(textInputObject->cursorPosition() != 0);
+    QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+    QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+
+    // Test delegate gets moved on mouse drag
+    textInputObject->setCursorPosition(0);
+    const QPoint point2 = textInputObject->positionToRectangle(10).center().toPoint();
+    QTest::qWait(400);  //ensure this isn't treated as a double-click
+    QTest::mousePress(&view, Qt::LeftButton, 0, point1);
+    QMouseEvent mv(QEvent::MouseMove, point2, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+    QGuiApplication::sendEvent(&view, &mv);
+    QTest::mouseRelease(&view, Qt::LeftButton, 0, point2);
+    QTest::qWait(50);
+    QTRY_COMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+    QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+
+    textInputObject->setReadOnly(true);
+    textInputObject->setCursorPosition(0);
+    QTest::qWait(400);  //ensure this isn't treated as a double-click
+    QTest::mouseClick(&view, Qt::LeftButton, 0, textInputObject->positionToRectangle(5).center().toPoint());
+    QTest::qWait(50);
+    QTRY_VERIFY(textInputObject->cursorPosition() != 0);
+    QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+    QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+
+    textInputObject->setCursorPosition(0);
+    QTest::qWait(400);  //ensure this isn't treated as a double-click
+    QTest::mouseClick(&view, Qt::LeftButton, 0, textInputObject->positionToRectangle(5).center().toPoint());
+    QTest::qWait(50);
+    QTRY_VERIFY(textInputObject->cursorPosition() != 0);
+    QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+    QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+
+    textInputObject->setCursorPosition(0);
+    QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+    QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+
+    // Delegate moved when text is entered
+    textInputObject->setText(QString());
+    for (int i = 0; i < 20; ++i) {
+        QTest::keyClick(&view, Qt::Key_A);
+        QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+    }
+
+    // Delegate moved when text is entered by im.
+    textInputObject->setText(QString());
+    for (int i = 0; i < 20; ++i) {
+        QInputMethodEvent event;
+        event.setCommitString("a");
+        QGuiApplication::sendEvent(&view, &event);
+        QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
+        QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
+    }
+
     //Test Delegate gets deleted
     textInputObject->setCursorDelegate(0);
     QVERIFY(!textInputObject->findChild<QQuickItem*>("cursorInstance"));
@@ -3201,18 +3265,23 @@ void tst_qquicktextinput::preeditCursorRectangle()
     QQuickTextInput *input = qobject_cast<QQuickTextInput *>(view.rootObject());
     QVERIFY(input);
 
-    QRect currentRect;
+    QQuickItem *cursor = input->findChild<QQuickItem *>("cursor");
+    QVERIFY(cursor);
+
+    QRectF currentRect;
 
     QInputMethodQueryEvent query(Qt::ImCursorRectangle);
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-    QRect previousRect = query.value(Qt::ImCursorRectangle).toRect();
+    QRectF previousRect = query.value(Qt::ImCursorRectangle).toRectF();
 
     // Verify that the micro focus rect is positioned the same for position 0 as
     // it would be if there was no preedit text.
     sendPreeditText(preeditText, 0);
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-    currentRect = query.value(Qt::ImCursorRectangle).toRect();
+    currentRect = query.value(Qt::ImCursorRectangle).toRectF();
     QCOMPARE(currentRect, previousRect);
+    QCOMPARE(input->cursorRectangle(), currentRect);
+    QCOMPARE(cursor->pos(), currentRect.topLeft());
 
     QSignalSpy inputSpy(input, SIGNAL(cursorRectangleChanged()));
     QSignalSpy panelSpy(qGuiApp->inputMethod(), SIGNAL(cursorRectangleChanged()));
@@ -3222,8 +3291,10 @@ void tst_qquicktextinput::preeditCursorRectangle()
     for (int i = 1; i <= 5; ++i) {
         sendPreeditText(preeditText, i);
         QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-        currentRect = query.value(Qt::ImCursorRectangle).toRect();
+        currentRect = query.value(Qt::ImCursorRectangle).toRectF();
         QVERIFY(previousRect.left() < currentRect.left());
+        QCOMPARE(input->cursorRectangle(), currentRect);
+        QCOMPARE(cursor->pos(), currentRect.topLeft());
         QVERIFY(inputSpy.count() > 0); inputSpy.clear();
         QVERIFY(panelSpy.count() > 0); panelSpy.clear();
         previousRect = currentRect;
@@ -3235,8 +3306,10 @@ void tst_qquicktextinput::preeditCursorRectangle()
     QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>());
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent);
     QCoreApplication::sendEvent(qGuiApp->focusObject(), &query);
-    currentRect = query.value(Qt::ImCursorRectangle).toRect();
+    currentRect = query.value(Qt::ImCursorRectangle).toRectF();
     QCOMPARE(currentRect, previousRect);
+    QCOMPARE(input->cursorRectangle(), currentRect);
+    QCOMPARE(cursor->pos(), currentRect.topLeft());
     QVERIFY(inputSpy.count() > 0);
     QVERIFY(panelSpy.count() > 0);
 }