Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with displaying substraction
Qt 6.11 is out! See what's new in the release blog

Problem with displaying substraction

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 787 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • D Damian7546

      @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.

      D Offline
      D Offline
      Damian7546
      wrote on last edited by
      #6

      I changed signal from onCursorPositionChanged to onTextValueChanged and works

      1 Reply Last reply
      0
      • D Damian7546

        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?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @Damian7546
        I don't use QML, but does it matter that you have misspelled onCursorPossitionChanged here? Should be onCursorPositionChanged?

        D 1 Reply Last reply
        0
        • JonBJ JonB

          @Damian7546
          I don't use QML, but does it matter that you have misspelled onCursorPossitionChanged here? Should be onCursorPositionChanged?

          D Offline
          D Offline
          Damian7546
          wrote on last edited by
          #3

          @JonB you are right, typo when rewriting on the forum, but it is not a problem....

          JonBJ 1 Reply Last reply
          0
          • D Damian7546

            @JonB you are right, typo when rewriting on the forum, but it is not a problem....

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @Damian7546
            Show exactly what is in paid.text and toPay.text. I think you are in JavaScript and something like console.log(paid.text) should work? And I think you can also call parseInt(paid.text) to see what number JS parses it as.

            D 1 Reply Last reply
            0
            • JonBJ JonB

              @Damian7546
              Show exactly what is in paid.text and toPay.text. I think you are in JavaScript and something like console.log(paid.text) should work? And I think you can also call parseInt(paid.text) to see what number JS parses it as.

              D Offline
              D Offline
              Damian7546
              wrote on last edited by Damian7546
              #5

              @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.

              D 1 Reply Last reply
              0
              • D Damian7546

                @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.

                D Offline
                D Offline
                Damian7546
                wrote on last edited by
                #6

                I changed signal from onCursorPositionChanged to onTextValueChanged and works

                1 Reply Last reply
                0
                • D Damian7546 has marked this topic as solved on

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved