[Interest] Android keybaord rect

Jason H jhihn at gmx.com
Thu Nov 3 18:17:48 CET 2016


For chat style apps, it is often desired to not to obscure the bottom of the screen. There are a two ways to handle this on Android. One is to resize the Window to be height - keybaord.height, the other is to just pad the UI with an element the height of the keyboard rectangle.  The problem is in Qt, the Qt.inputMethod.keyboardRectangle.height is not accurate. It's correct on some devices, off (too big or too small) on others. Has anyone successfully implemented something like this? I tried to divide by devicePixelRatio, but it did not work.

Qt version 5.6.2

{
// ... at bottom of the layout ...
	Connections {
		target: Qt.inputMethod
		onKeyboardRectangleChanged: {
			console.log("Qt.inputMethod.visible:", Qt.inputMethod.visible, Qt.inputMethod.keyboardRectangle.height)
			keyboardSpacer.height = (Qt.platform.os === "android") ? Qt.inputMethod.keyboardRectangle.height / Screen.devicePixelRatio: 0;
			listView.positionViewAtEnd()
		}
	}
	Item {
		id: keyboardSpacer
		height: 0
		anchors{
			left: parent.left
			right: parent.right
			bottom: parent.bottom
		}
	}
}



More information about the Interest mailing list