Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to decrement spinbox values.
Forum Updated to NodeBB v4.3 + New Features

how to decrement spinbox values.

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 6 Posters 1.5k Views 4 Watching
  • 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 Offline
    L Offline
    Leopold
    wrote on last edited by
    #1

    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
    0
    • L Leopold

      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 Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leopold
        wrote on last edited by
        #3

        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

        JonBJ K 2 Replies Last reply
        0
        • L Leopold

          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

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

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

          1 Reply Last reply
          1
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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
            0
            • L Leopold

              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

              K Offline
              K Offline
              kenchan
              wrote on last edited by kenchan
              #6

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

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leopold
                wrote on last edited by
                #7

                @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
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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
                  0
                  • mranger90M Offline
                    mranger90M Offline
                    mranger90
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      Leopold
                      wrote on last edited by
                      #10

                      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. RoginaP 1 Reply Last reply
                      0
                      • L Leopold

                        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. RoginaP Offline
                        Pablo J. RoginaP Offline
                        Pablo J. Rogina
                        wrote on last edited by
                        #11

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

                        • Login

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