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. Spinbox Totals
Qt 6.11 is out! See what's new in the release blog

Spinbox Totals

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 3.8k Views 1 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.
  • A Offline
    A Offline
    Aggroblakh
    wrote on last edited by
    #1

    Hey, for anyone that has experience using Qt and C++,

    Say I have a group of spin boxes, the total values of which need to add up to a certain amount. It is easy enough to disable them all once I reach that amount by using the up/down arrows, but since the user can enter the values manually, they can still exceed the total before I can disable them (since the valueChanged signal would fire AFTER they change the value).

    Is there a way to somehow link the values of the spin boxes together so that for instance, if I have 3 spin boxes with values 5, 5 and 0, and the max is 12, the third box can only be set to 2?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Yes: write it yourself and set the maximum ranges every time the user changes any spinbox. :P

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

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

        You should remember the old values of the spinbox then when user change the value of a spinbox, if it exceed the maximum you set the old value.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Aggroblakh
          wrote on last edited by
          #4

          Hmmm... how do I remember the old values of the spinbox? The valueChanged signal takes the number AFTER it has already been changed.

          The way I have it now, everytime a value is changed, it adds the values of all the spin boxes and subtracts from the final total. Then, if the current value is over a certain amount, it just sets the maximum of all the spinboxes to the max total - the current total. This works, but it seems like a hack.

          Thanks for the prompt replies by the way =D

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            You can store the initial values somewhere and update them after an valueChanged signal was send and accepted?

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              why not reimplement validate() ?

              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