Android: How to move views above keyboard when it’s opened (Qml)
-
I have a Qml ApplicationWindow with Rectangles(Forms),Listmodel delegates, and many other Items. The problem I have is that the Android Key board on android device, which appears when filling Forms blocks some input fields and buttons especially when getting responses from server because the Keyboard does not stay below the views.
Is there a way to get the android keyboard to below the view or Applicationwindow in Qml especial when a new view appears. -
I have a Qml ApplicationWindow with Rectangles(Forms),Listmodel delegates, and many other Items. The problem I have is that the Android Key board on android device, which appears when filling Forms blocks some input fields and buttons especially when getting responses from server because the Keyboard does not stay below the views.
Is there a way to get the android keyboard to below the view or Applicationwindow in Qml especial when a new view appears. -
There is a Textinput field(e.g. TextField) which causes the keyboard to popup when a cursor is available .If for example, I press submit button to send data to server, when the response comes back the keyboard does not hide which usually blocks some input fields or buttons that appear with the new view or window.
If the keyboard could hide when the submit button is pressed or when there response comes back it could be an alternative solution. The best solution however is to have the Keyboard below the view or window . Android Studio has the functionality to move views(whole App) up above the keyboard. -
There is a Textinput field(e.g. TextField) which causes the keyboard to popup when a cursor is available .If for example, I press submit button to send data to server, when the response comes back the keyboard does not hide which usually blocks some input fields or buttons that appear with the new view or window.
If the keyboard could hide when the submit button is pressed or when there response comes back it could be an alternative solution. The best solution however is to have the Keyboard below the view or window . Android Studio has the functionality to move views(whole App) up above the keyboard. -
Setting TextInput focus to false when response comes back works fine but in my case I also have to handle key input especial the back button .the focus I set to true cancels out the Textinput focus and it fails to function . Here is an example code -
import QtQuick
//import QtQuick.VirtualKeyboard
import QtQuick.Controls
import Qt.labs.platform
import QtQuick 2.0Window {
id: window
width: 200
height: 480
visible: true
title: qsTr("Hello World")Rectangle { width: 250; height: 400 color: "green" TextEdit { id:hhh width: 240 height: 40 text: " " font.family: "Helvetica" font.pointSize: 20 color: "blue" focus: true } MouseArea{ anchors.fill: parent onClicked: { hhh.focus= false parent.color = 'red' } } MessageDialog { id: noPublic title: "Track Gate" text: "move left" onAccepted: { } } MessageDialog { id: noPublic1 title: "Track Gate" text: "Pressed return" onAccepted: { } } focus: true Keys.onPressed: (event)=> { if (event.key === Qt.Key_Left) { console.log("move left"); noPublic.open() event.accepted = true; } } Keys.onReturnPressed: { noPublic1.open() console.log("Pressed return"); }
}
} -
Setting TextInput focus to false when response comes back works fine but in my case I also have to handle key input especial the back button .the focus I set to true cancels out the Textinput focus and it fails to function . Here is an example code -
import QtQuick
//import QtQuick.VirtualKeyboard
import QtQuick.Controls
import Qt.labs.platform
import QtQuick 2.0Window {
id: window
width: 200
height: 480
visible: true
title: qsTr("Hello World")Rectangle { width: 250; height: 400 color: "green" TextEdit { id:hhh width: 240 height: 40 text: " " font.family: "Helvetica" font.pointSize: 20 color: "blue" focus: true } MouseArea{ anchors.fill: parent onClicked: { hhh.focus= false parent.color = 'red' } } MessageDialog { id: noPublic title: "Track Gate" text: "move left" onAccepted: { } } MessageDialog { id: noPublic1 title: "Track Gate" text: "Pressed return" onAccepted: { } } focus: true Keys.onPressed: (event)=> { if (event.key === Qt.Key_Left) { console.log("move left"); noPublic.open() event.accepted = true; } } Keys.onReturnPressed: { noPublic1.open() console.log("Pressed return"); }
}
}@track you can also have a "secondary" root object, that one you can move to your hearts content:
For Example:
ApplicationWindow { id:mainwindow height: 768 width: 1280 visible: true title: qsTr("My App") color: "white" minimumHeight: 768 minimumWidth: 1280 Item{ id: root width:parent.width height: parent.height //rest of your app content in here } }
than you can manipulate
y
property of root, to move it "up" when you show keyboard input -
Using J.Hilk and JoeCFD's last response, I am able to get the solution for my use case. When I click on the secondary root object ,the TextEdit focus is set to false and the android keyboard hides allowing the secondary root item focus to be true. The code to accomplish the above mentioned :
ApplicationWindow {
id:mainwindow
height: 400
width: 250
visible: truetitle: qsTr("My App") color: "white"
// minimumHeight: 768
// minimumWidth: 1280
Item{
id: root
width:parent.width
height: parent.height
y:0
anchors.centerIn: parent
//rest of your app content in here
Rectangle {width: 250; height: 400 color: "green" anchors.centerIn: parent Rectangle { width: 240; height: 40 color: "yellow" z:200 anchors.horizontalCenter: parent.horizontalCenter TextEdit { id:hhh width:parent.width height: parent.height text: " " font.family: "Helvetica" font.pointSize: 20 color: "blue" focus: true } } MouseArea{ anchors.fill: parent onClicked: { hhh.focus= false
//noPublic.open()
console.log("Clicked")
// parent.color = 'red'
}} MessageDialog { id: noPublic title: "Track Gate" text: "move left" onAccepted: { } } MessageDialog { id: noPublic1 title: "Track Gate" text: "Pressed return" onAccepted: { } }
}
focus: true Keys.onPressed: (event)=> { if (event.key === Qt.Key_Left) { console.log("move left"); noPublic.open() event.accepted = true; } } Keys.onReturnPressed: { noPublic1.open() console.log("Pressed return"); } }
}
Thanks one more time for your quick assistance.