02-12-2013 12:27 PM
Hello,
I am having a few issues with updating the textfield. Ideally my outcome would be for after the user inputs their numeric value and focus changes the measurement unit gets added.
For Example:
User Enters: 30 --> Final Value: 30 ft
Currently I am have this:
TextField {
Id: input_val
onTextChanging: {
input_val.text = Calc.numericOnly(text);
}
onTextChanged: {
textOuput.text = Calculate(input_val.text)
}
}
I have tried changing:
input_val.text = Calc.numericOnly(text);
to
input_val.text = qsTr(“%1 %2”).arg(Calc.numericOnly(text)).arg(mainTab.mValu
in onTextChanging. All this has done is add the unit all of the time, even when there is no value in the text area. You cannot get rid of it at this point, which is a tad annoying. It of course also adds the unit after the user enters the first digit. Ideally it would be nice to add once the textfield has lost focussed. Therefore I tried adding:
onFocusedChanged: {
input_val.text = qsTr(“%1 %2”).arg(Calc.numericOnly(text)).arg(mainTab.mValu
}
After OnTextChanging and nothing happens. So I then moved tried to put:
input_val.text = qsTr(“%1 %2”).arg(Calc.numericOnly(text)).arg(mainTab.mValu
inside the OnTextChanged signal, which causes the program to crash.
Is there something really simple I am missing? Any help would be very much appreciated.
Sincerely
D
02-13-2013 12:32 AM
Can you try if this one works?
TextField {
id: txtFt
inputMode: TextFieldInputMode.NumbersAndPunctuation
onFocusedChanged: {
if(!focused)
{
txtFt.text = appendFt(txtFt.text);
}
else
{
txtFt.text = removeFt(txtFt.text);
}
}
function appendFt(txtVal)
{
if(txtVal.length > 0)
return txtVal + "ft";
else
return txtVal;
}
function removeFt(txtVal)
{
return txtVal.replace("ft", "");
}
}
- Dishooom
Hope this helps ![]()