diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index c38f3db7a19..aad75207a1c 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1802,6 +1802,22 @@ void QLineEdit::inputMethodEvent(QInputMethodEvent *e) */ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const { +#ifdef Q_OS_ANDROID + // QTBUG-61652 + if (property == Qt::ImEnterKeyType) { + QWidget *next = nextInFocusChain(); + while (next && next != this && next->focusPolicy() == Qt::NoFocus) + next = next->nextInFocusChain(); + if (next) { + const auto nextYPos = next->mapToGlobal(QPoint(0, 0)).y(); + const auto currentYPos = mapToGlobal(QPoint(0, 0)).y(); + if (currentYPos < nextYPos) + // Set EnterKey to KeyNext type only if the next widget + // in the focus chain is below current QLineEdit + return Qt::EnterKeyNext; + } + } +#endif return inputMethodQuery(property, QVariant()); } diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 74a011d96dc..efd59059d09 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -267,6 +267,8 @@ private slots: void inputMethodQueryImHints_data(); void inputMethodQueryImHints(); + void inputMethodQueryEnterKeyType(); + void inputMethodUpdate(); void undoRedoAndEchoModes_data(); @@ -4409,6 +4411,33 @@ void tst_QLineEdit::inputMethodQueryImHints() QCOMPARE(static_cast(value.toInt()), hints); } +void tst_QLineEdit::inputMethodQueryEnterKeyType() +{ + QWidget mw; + QVBoxLayout layout(&mw); + QLineEdit le1(&mw); + layout.addWidget(&le1); + mw.show(); + QVariant enterType = le1.inputMethodQuery(Qt::ImEnterKeyType); + QCOMPARE(enterType.value(), Qt::EnterKeyDefault); + + mw.hide(); + QLineEdit le2(&mw); + layout.addWidget(&le2); + mw.show(); + + enterType = le1.inputMethodQuery(Qt::ImEnterKeyType); +#ifdef Q_OS_ANDROID + // QTBUG-61652 + // EnterKey is changed to EnterKeyNext if the focus can be moved to widget below + QCOMPARE(enterType.value(), Qt::EnterKeyNext); +#else + QCOMPARE(enterType.value(), Qt::EnterKeyDefault); +#endif + enterType = le2.inputMethodQuery(Qt::ImEnterKeyType); + QCOMPARE(enterType.value(), Qt::EnterKeyDefault); +} + void tst_QLineEdit::inputMethodUpdate() { if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))