Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved how to decrement spinbox values.

    General and Desktop
    6
    11
    1031
    Loading More Posts
    • 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.
    • L
      Leopold last edited by

      I know i have to use setValue but i want to increment and decrement by events.
      I have inside a void:
      m_ui->spinBox-> setValue(m_ui->spinBox-> value()+1)
      this works perfect.Now I want to decrement with:
      m_ui->spinBox-> setValue(m_ui->spinBox-> value()-1)
      this does not work.
      How can I solve that?

      K 1 Reply Last reply Reply Quote 0
      • K
        kenchan @Leopold last edited by

        @Leopold
        so is the minimum range set to allow for negative values?

        1 Reply Last reply Reply Quote 0
        • L
          Leopold last edited by

          Hello,
          I don't want negative values, i want to decrement.
          spinBox = 0.
          m_ui->spinBox-> setValue(m_ui->spinBox-> value()+1)
          spiBox=1
          m_ui->spinBox-> setValue(m_ui->spinBox-> value()+1)
          spinBox=2
          m_ui->spinBox-> setValue(m_ui->spinBox-> value()-1)
          spinBox stays at 2 should become 1

          JonB K 2 Replies Last reply Reply Quote 0
          • JonB
            JonB @Leopold last edited by

            @Leopold
            Your code looks fine, so it must be something else....

            1 Reply Last reply Reply Quote 1
            • mrjj
              mrjj Lifetime Qt Champion last edited by

              Hi
              I agree with @JonB . That should just work.
              Did you try

              m_ui->spinBox-> setValue(1);
              m_ui->spinBox-> setValue(2);
              m_ui->spinBox-> setValue(1);
              
              1 Reply Last reply Reply Quote 0
              • K
                kenchan @Leopold last edited by kenchan

                @Leopold yes, i see. as the others say the code looks correct so i was just fishing :-)

                1 Reply Last reply Reply Quote 0
                • L
                  Leopold last edited by

                  @mrjj
                  yes, direct settings work,
                  increment is good too but decrement with:
                  m_ui->spinBox-> setValue(m_ui->spinBox-> value()-1)
                  spinBox stays at 2 should become 1
                  is not working.
                  Any an other idea for decrementing by 1 step?
                  Decrementing by arrows is possible so it should be possible by code too.

                  1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion last edited by

                    Hi
                    Try to do it outside a slot.
                    I think its related to the event loop and how you trigger setValue slot.
                    Setting the values directly works so it must drop a setValue or something
                    like that.

                    1 Reply Last reply Reply Quote 0
                    • mranger90
                      mranger90 last edited by

                      Are you perhaps handling the spinbox valueChanged() signal and inadvertently blocking the new value ?

                      1 Reply Last reply Reply Quote 0
                      • L
                        Leopold last edited by

                        Sorry for bothering,
                        the code works,it was my fault within an if else.
                        first i incremented,then i decremented so it looked as if nothing had happened.

                        Pablo J. Rogina 1 Reply Last reply Reply Quote 0
                        • Pablo J. Rogina
                          Pablo J. Rogina @Leopold last edited by

                          @Leopold is your issue solved? If so, please don't forget to mark your post as such. Thanks.

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post