Problem with displaying substraction
-
Hi,
I have textField with id: rest.
In other TextField I calcualte value in
rest
like below :TextField{ id: paid onCursorPossitionChanged: { rest.text = paid.text - toPay.text } }
Usually displaying above substraction works good. But when I have paid = 5 and toPay=4 I have a problem because the
rest
textField dispaying 0 .... ? Any idea why? -
I changed signal from
onCursorPositionChanged
toonTextValueChanged
and works -
@Damian7546
I don't use QML, but does it matter that you have misspelledonCursorPossitionChanged
here? Should beonCursorPositionChanged
? -
@Damian7546
Show exactly what is inpaid.text
andtoPay.text
. I think you are in JavaScript and something likeconsole.log(paid.text)
should work? And I think you can also callparseInt(paid.text)
to see what number JS parses it as. -
@JonB Below part code:
TextField { id: paid width: 200 height: 50 onCursorPositionChanged: { rest.text = paid.text - toPay.text } font.pixelSize: paid.height * .7 Keys.onEnterPressed: { accountButton.focus = true } validator: IntValidator { bottom: 0 top: 500 } } TextField { id: rest width: 200 height: 50 enabled: false font.pixelSize: rest.height * .7 font.bold: true color: "black" background: Rectangle { color: rest.text !== "0" ? "orange" : "lightgray" border.color: "gray" } } TextField { id: toPay width: 200 height: 75 font.pixelSize: toPay.height * .5 text: _toPay color: "black" background: Rectangle { color: "lightgreen" } } //////Delay after popup onOpened Timer { id: timer interval: 200 onTriggered: { paid.text = _toPay paid.select(0,paid.length) rest.text = "0" } }
The problem is only when open popup. When I clear
rest
TextField and write again everything is ok. -
I changed signal from
onCursorPositionChanged
toonTextValueChanged
and works -