Impossible to detect keyboard visibility/size when using WebView on Android



  • So I am trying to find a way to detect whether the keyboard is visible in my Android application (Qt 5.11 on Linux, testing on Oreo). I have managed to do this partially using Qt.inputMethod.visible and also get the height with Qt.inputMethod.height. However, there is a big problem with this approach: it does not seem to work within a Qml WebView. When the use is visiting a webpage and hit a textfield, the previous method return 0 and hence I am unable to work out whether the keyboard is shown or not. Here is a sample code to reproduce the problem:

    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Window 2.2
    import QtQuick.Dialogs 1.2
    import QtWebView 1.0
    
    ApplicationWindow {
        title: qsTr("Hello World")
        width: 640
        height: 480
        visible: true
    
        Item{
            anchors.fill: parent
            WebView{
                id: webView
                url: "https://google.com"
                anchors.top: labelOut.bottom; anchors.bottom: parent.bottom
                anchors.left: parent.left; anchors.right: parent.right
            }
            Label {
                id: labelOut
                text: "Virtual Keyboard Visible: " + Qt.inputMethod.visible + " height: " + Qt.inputMethod.keyboardRectangle.height
                anchors.leftMargin: 4
                anchors.left: parent.left
                anchors.top: parent.top
                color: "black"
            }
    
        }
    }