PDA

View Full Version : QDoubleSpinBox with commit on every change functionality



Zanyinj
11th November 2011, 10:29
Good day,

I am trying to create a subclassed QDoubleSpinBox with the added functionality of commiting data on every valueChanged() signal.

The reason is that the spinbox is connected to a model via QDataWidgetMapper and the model is also controlling a plot. I want the plot to change instantly, which it does when the spinbox loses focus or enter is pressed, but I want it to change when the spinbox is changed in any way (mousewheel, up/down keys .. ect).

I have found a dirty way to force the commit - I connect the valueChanged signal to a slot that clears and sets the focus on the spinbox, commiting the data because it loses focus but regaining focus instantly. The side effect is that the buttons on the spinbox no longer visually lower themselves when clicked (they work though).

I have also checked the source of the QSpinBox and the QAbstractSpinBox to figure out how the data is commited when the enter key is pressed, but am unable to come up with a working solution. I have tried connecting the valueChanged() signal to the editingFinished() signal, i have tried running interpretText() and emiting editingFinished() on every valueChanged - but it does not seem to do what i want.

Is there an elegant way or even a not-so-elegant way to gain the desired functionality?

I am using Qt 4.7.2(64 bit) in Ubuntu 11.04 (64 bit).

Ginsengelf
16th November 2011, 08:33
Hi, have you tried to connect the valueChanged() signal to the submit() slot of the QDataWidgetMapper?

Ginsengelf

Zanyinj
17th November 2011, 08:45
Actually that ended up being the solution:) The only bothersome thing about it is the fact that all of the mapped widgets commit their data when only one of them is changed. It would be excellent to be able to commit only one mapped widget - e.g. submit(QWidget *).

It's not a huge bother to program around that, but it requires tweaking the model and the instant-commit functionality is required basically in all the applications I work on (honestly, I kind of expected that to be the default functionaly).