TextInput how to block entering new data if current value is out of range?
Solved
QML and Qt Quick
-
I'm looking for way to block entering new data if current value if out of range. I was check the
TextInput validator
property with a range but setting it just block possibility to press enter, not input new.I was tried to use onTextEdited and remove last character but new number is added after this, so in the end always remove one before last digit. Any idea?
onTextEdited: { if ((text < analogValid.bottom) || (text > analogValid.top)) { console.log("onTextEdited: " + text); textInputComp.remove(selectionEnd-1, selectionEnd); } }
-
IIm not sure if is it a proper way but i solved my problem. I just save the old value of
text
property in by bufferonTextEdited
.
TheonTextEdited
will be called before text will be changed. After that text will be changed and automaticly callingonTextChanged
wheretext
value will be checked.onTextEdited: { if ((validator === analogValid) && (text >= analogValid.bottom) && (text <= analogValid.top)) oldTextVal = text; } onTextChanged: { if ((validator === analogValid) && ((text < analogValid.bottom) || (text > analogValid.top))) text = oldTextVal; }