I'm trying to write a character counter for a TextEdit field.
I have tryed numerous ways that work fine on the desktop, but on Android it fails when the space key is pressed and then only works when space key is pressed.
What am I missing?
Printable View
I'm trying to write a character counter for a TextEdit field.
I have tryed numerous ways that work fine on the desktop, but on Android it fails when the space key is pressed and then only works when space key is pressed.
What am I missing?
I am not sure I understand.
The length of the text does not increase if spaces are added on Android?
Cheers,
_
No, here is some code that shows the problem:
Code:
import QtQuick 2.0 import QtQuick.Controls 1.3 Item { Rectangle { id: textin anchors.top: parent.top anchors.topMargin: parent.height / 10 width: parent.width * 0.8 height: parent.height / 3 anchors.horizontalCenter: parent.horizontalCenter border.color: "#000000" TextEdit { id: ptext anchors.fill: parent clip: true textMargin : 10 wrapMode : Text.WordWrap text: "test" onTextChanged: { textcount.text = ptext.text.length console.log(text, ptext.text.length) } } Text { id: textcount anchors.bottom: textin.bottom anchors.right: textin.right width: parent.width * 0.2 height: parent.height * 0.2 } } }
qrc:/debug.qml:19 (onTextChanged): qml: test 4
qrc:/debug.qml:19 (onTextChanged): qml: testa 5
qrc:/debug.qml:19 (onTextChanged): qml: testab 6
qrc:/debug.qml:19 (onTextChanged): qml: testabc 7
qrc:/debug.qml:19 (onTextChanged): qml: testabc 8
qrc:/debug.qml:19 (onTextChanged): qml: testabc 8
qrc:/debug.qml:19 (onTextChanged): qml: testabc 8
qrc:/debug.qml:19 (onTextChanged): qml: testabc 8
qrc:/debug.qml:19 (onTextChanged): qml: testabc 8
qrc:/debug.qml:19 (onTextChanged): qml: testabc test 12
qrc:/debug.qml:19 (onTextChanged): qml: testabc test 13
So after the first space the text doesn't actually change until the next space?
I wonder why that triggers onTextChanged at all.
Maybe the input method or virtual keyboard on Android holds modifications back, e.g. for auto completion, etc.?
Cheers,
_
Yes thats the problem.
I don't use auto-completion and the characters show in the TextEdit field.
Any idea how to write a text lenght counter in QML that works on Android?
Cheers,