TextEdit maximum text length
-
Does anyone know how to make text in TextEdit element constrained to specified number of characters?
I am using following approach:@ onTextChanged: {
if (!readOnly && text.length > 10)
{
var cpos = cursorPosition
text = text.slice(0, 10 - text.length)
if (cpos >= text.length)
cursorPosition = text.length
else
cursorPosition = cpos
}
if (paintedHeight > height)
{
parent.height = paintedHeight+6
}
}
@It works, but on my C7 automatic removing of a last char(after exceeding 10 chars) is not immediate.
Also when writing in the middle of text sometimes input is set to upper-case letters instead of lower-case. -
Why not subclass [[Doc:QValidator]], and check the length of the input string there? Simply re-implement validate() and fixup. validate() would just return Acceptable for strings shorter or equal than the required length, and Invalid for longer strings. fixup() would simply truncate the input text.
-