PDA

View Full Version : Android, character counter for TextEdit



blackdog
30th May 2016, 22:16
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?

anda_skoa
31st May 2016, 09:16
I am not sure I understand.
The length of the text does not increase if spaces are added on Android?

Cheers,
_

blackdog
31st May 2016, 22:58
No, here is some code that shows the problem:


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

anda_skoa
1st June 2016, 08:50
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,
_

blackdog
1st June 2016, 22:33
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,