diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 619577d93fa3bcd3642097056c8839c533e3a620..ab9fb66fb1c3e4bbe8980f3ec91d2b0bba1190eb 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -917,6 +917,9 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event)
     case QEvent::InputMethod:
         handleInputMethodEvent(static_cast<QInputMethodEvent*>(event));
         break;
+    case QEvent::InputMethodQuery:
+        handleInputMethodQueryEvent(static_cast<QInputMethodQueryEvent*>(event));
+        break;
     default:
         return false;
     }
@@ -1258,6 +1261,19 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
     }
 }
 
+void RenderWidgetHostViewQt::handleInputMethodQueryEvent(QInputMethodQueryEvent *ev)
+{
+    Qt::InputMethodQueries queries = ev->queries();
+    for (uint i = 0; i < 32; ++i) {
+        Qt::InputMethodQuery query = (Qt::InputMethodQuery)(int)(queries & (1<<i));
+        if (query) {
+            QVariant v = inputMethodQuery(query);
+            ev->setValue(query, v);
+        }
+    }
+    ev->accept();
+}
+
 #ifndef QT_NO_ACCESSIBILITY
 void RenderWidgetHostViewQt::accessibilityActiveChanged(bool active)
 {
diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h
index 78b946a605e74aaf0e53abb7be20ff9eb40e1cd4..304fa0e1aefb693b060de5e77f791edd2d14be9a 100644
--- a/src/core/render_widget_host_view_qt.h
+++ b/src/core/render_widget_host_view_qt.h
@@ -192,6 +192,7 @@ public:
     void handleHoverEvent(QHoverEvent*);
     void handleFocusEvent(QFocusEvent*);
     void handleInputMethodEvent(QInputMethodEvent*);
+    void handleInputMethodQueryEvent(QInputMethodQueryEvent*);
 
 #if defined(OS_MACOSX)
     virtual void SetActive(bool active) Q_DECL_OVERRIDE { QT_NOT_YET_IMPLEMENTED }
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 82e50409d6f602dbd32648554cda2b5340d8c41e..75795c17051866e6a7f486d29870003074e23bda 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -102,6 +102,8 @@ private Q_SLOTS:
     void hiddenText();
     void emptyInputMethodEvent();
     void imeComposition();
+    void imeCompositionQueryEvent_data();
+    void imeCompositionQueryEvent();
     void newlineInTextarea();
 };
 
@@ -1935,5 +1937,83 @@ void tst_QWebEngineView::newlineInTextarea()
     QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("\n\nthird line"));
 }
 
+void tst_QWebEngineView::imeCompositionQueryEvent_data()
+{
+    QTest::addColumn<QString>("receiverObjectName");
+    QTest::newRow("focusObject") << QString("focusObject");
+    QTest::newRow("focusProxy") << QString("focusProxy");
+    QTest::newRow("focusWidget") << QString("focusWidget");
+}
+
+void tst_QWebEngineView::imeCompositionQueryEvent()
+{
+    QWebEngineView view;
+    view.show();
+
+    QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool)));
+    view.setHtml("<html><body>"
+                 "  <input type='text' id='input1' />"
+                 "</body></html>");
+    QVERIFY(loadFinishedSpy.wait());
+
+    evaluateJavaScriptSync(view.page(), "document.getElementById('input1').focus()");
+    QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("input1"));
+
+    QObject *input = nullptr;
+
+    QFETCH(QString, receiverObjectName);
+    if (receiverObjectName == "focusObject")
+        input = qApp->focusObject();
+    else if (receiverObjectName == "focusProxy")
+        input = view.focusProxy();
+    else if (receiverObjectName == "focusWidget")
+        input = view.focusWidget();
+
+    QVERIFY(input);
+
+    QInputMethodQueryEvent srrndTextQuery(Qt::ImSurroundingText);
+    QInputMethodQueryEvent cursorPosQuery(Qt::ImCursorPosition);
+    QInputMethodQueryEvent anchorPosQuery(Qt::ImAnchorPosition);
+
+    // Set composition
+    {
+        QList<QInputMethodEvent::Attribute> attributes;
+        QInputMethodEvent event("composition", attributes);
+        QApplication::sendEvent(input, &event);
+        qApp->processEvents();
+    }
+    QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("composition"));
+    QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImCursorPosition).toInt(), 11);
+
+    QApplication::sendEvent(input, &srrndTextQuery);
+    QApplication::sendEvent(input, &cursorPosQuery);
+    QApplication::sendEvent(input, &anchorPosQuery);
+    qApp->processEvents();
+
+    QTRY_COMPARE(srrndTextQuery.value(Qt::ImSurroundingText).toString(), QString(""));
+    QTRY_COMPARE(cursorPosQuery.value(Qt::ImCursorPosition).toInt(), 11);
+    QTRY_COMPARE(anchorPosQuery.value(Qt::ImAnchorPosition).toInt(), 11);
+
+    // Send commit
+    {
+        QList<QInputMethodEvent::Attribute> attributes;
+        QInputMethodEvent event("", attributes);
+        event.setCommitString("composition");
+        QApplication::sendEvent(input, &event);
+        qApp->processEvents();
+    }
+    QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QString("composition"));
+    QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("composition"));
+
+    QApplication::sendEvent(input, &srrndTextQuery);
+    QApplication::sendEvent(input, &cursorPosQuery);
+    QApplication::sendEvent(input, &anchorPosQuery);
+    qApp->processEvents();
+
+    QTRY_COMPARE(srrndTextQuery.value(Qt::ImSurroundingText).toString(), QString("composition"));
+    QTRY_COMPARE(cursorPosQuery.value(Qt::ImCursorPosition).toInt(), 11);
+    QTRY_COMPARE(anchorPosQuery.value(Qt::ImAnchorPosition).toInt(), 11);
+}
+
 QTEST_MAIN(tst_QWebEngineView)
 #include "tst_qwebengineview.moc"