diff options
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.cpp | 22 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 40 |
2 files changed, 20 insertions, 42 deletions
diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index b8d29378de..b01f391a73 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -1194,13 +1194,21 @@ bool QAndroidInputContext::focusObjectStopComposing() m_composingCursor = -1; - // commit composing text and cursor position - QList<QInputMethodEvent::Attribute> attributes; - attributes.append( - QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0)); - QInputMethodEvent event(QString(), attributes); - event.setCommitString(m_composingText); - sendInputMethodEvent(&event); + { + // commit the composing test + QList<QInputMethodEvent::Attribute> attributes; + QInputMethodEvent event(QString(), attributes); + event.setCommitString(m_composingText); + sendInputMethodEvent(&event); + } + { + // Moving Qt's cursor to where the preedit cursor used to be + QList<QInputMethodEvent::Attribute> attributes; + attributes.append( + QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0)); + QInputMethodEvent event(QString(), attributes); + sendInputMethodEvent(&event); + } return true; } diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 208627394d..be185c1e7a 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -1595,44 +1595,14 @@ void tst_QLineEdit::textMask() QCOMPARE( testWidget->text(), insertString ); } -class LineEditChangingText : public QLineEdit -{ - Q_OBJECT - -public: - LineEditChangingText(QWidget *parent) : QLineEdit(parent) - { - connect(this, &QLineEdit::textEdited, this, &LineEditChangingText::onTextEdited); - } - -public slots: - void onTextEdited(const QString &text) - { - if (text.length() == 3) - setText(text + "-"); - } -}; - void tst_QLineEdit::setText() { QLineEdit *testWidget = ensureTestWidget(); - { - QSignalSpy editedSpy(testWidget, &QLineEdit::textEdited); - QSignalSpy changedSpy(testWidget, &QLineEdit::textChanged); - testWidget->setText("hello"); - QCOMPARE(editedSpy.size(), 0); - QCOMPARE(changedSpy.value(0).value(0).toString(), QString("hello")); - } - - QTestEventList keys; - keys.addKeyClick(Qt::Key_A); - keys.addKeyClick(Qt::Key_B); - keys.addKeyClick(Qt::Key_C); - - LineEditChangingText lineEdit(nullptr); - keys.simulate(&lineEdit); - QCOMPARE(lineEdit.text(), "abc-"); - QCOMPARE(lineEdit.cursorPosition(), 4); + QSignalSpy editedSpy(testWidget, SIGNAL(textEdited(QString))); + QSignalSpy changedSpy(testWidget, SIGNAL(textChanged(QString))); + testWidget->setText("hello"); + QCOMPARE(editedSpy.size(), 0); + QCOMPARE(changedSpy.value(0).value(0).toString(), QString("hello")); } void tst_QLineEdit::displayText_data() |