Important: Please read the Qt Code of Conduct -

Spinbox Totals

  • 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?

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

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

  • 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

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

  • why not reimplement validate() ?

Log in to reply