0

I’ve noticed that when the virtual keyboard opens in a QML application on iOS and Android, the screen shifts upward to keep the text input field in view. I’d like to implement my own custom mechanism for handling this, something similar to how KeyboardAvoidingView works in React Native, by adjusting the layout when the keyboard appears.

How to completely disable this default behavior when the keyboard opens?

enter image description here

import QtQuick

Window {
    visible: true
    flags: Qt.MaximizeUsingFullscreenGeometryHint

    MouseArea {
      anchors.fill: parent
      onClicked: forceActiveFocus()
    }

    Rectangle {
        anchors.fill: parent
        color: "#f5f5f5"

        Text {
            anchors {
                top: parent.top
                left: parent.left
                right: parent.right
                bottom: inputBox.top
                margins: 10
            }
            wrapMode: Text.WordWrap
            text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        }

        Rectangle {
            height: 60
            anchors {
                left: parent.left
                right: parent.right
                bottom: parent.bottom
                margins: 10
            }
            color: "white"
            radius: 8
            border.color: "#ddd"

            TextInput {
                anchors {
                    fill: parent
                    margins: 8
                }
                text: "Text input control"
            }
        }

    }
}
1
  • You can't on Android. The OS handles it. Your options are resize (the OS will resize your app to take the space on top of the keyboard) and pan (the keyboard will cover your app, and the OS will scroll your screen such that the cursor will always on on screen,. There is no way to customize beyond that. Also there is no way to be 100% sure of whether a keyboard is shown or not in Android- no such API exists. You can make guesses which some apps do based on resize events, but it will be wrong some percentage of the time and not work with all keyboards. Commented Apr 5 at 22:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.