Problem with displaying substraction
-
Hi,
I have textField with id: rest.
In other TextField I calcualte value in
restlike 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
resttextField dispaying 0 .... ? Any idea why? -
@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
restTextField and write again everything is ok.I changed signal from
onCursorPositionChangedtoonTextValueChangedand works -
Hi,
I have textField with id: rest.
In other TextField I calcualte value in
restlike 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
resttextField dispaying 0 .... ? Any idea why?@Damian7546
I don't use QML, but does it matter that you have misspelledonCursorPossitionChangedhere? Should beonCursorPositionChanged? -
@Damian7546
I don't use QML, but does it matter that you have misspelledonCursorPossitionChangedhere? Should beonCursorPositionChanged?@JonB you are right, typo when rewriting on the forum, but it is not a problem....
-
@JonB you are right, typo when rewriting on the forum, but it is not a problem....
@Damian7546
Show exactly what is inpaid.textandtoPay.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. -
@Damian7546
Show exactly what is inpaid.textandtoPay.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
restTextField and write again everything is ok. -
@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
restTextField and write again everything is ok.I changed signal from
onCursorPositionChangedtoonTextValueChangedand works -
D Damian7546 has marked this topic as solved on