Unsolved Auto Update Model in QWidgetMapper
-
Hello
I use QWidgetMapper with a few QlineEdit for editing data in model. when user edit fields in QLineEdit the new data will placed in the model when the enter key( or changing the focus) is pressed. I want to change this behavior so I need the data within the model change on the fly. I mean that data in model change as soon as possible user enter any key without waiting for enter key or changing widget focus.
Is there any way to accomplish this kind of behavior? -
This is not supported by QDataWidgetMapper, you have to write it by your own.
-
@hadi_m
I do this on a widget mapper for a whole bunch ofQSpinBox
es. I connect toQSpinBox::valueChanged
and the slot callsQDataWidgetMapper::submit()
to update the model immediately. It works a treat :)Presumably you can do the same against
QLineEdit::textEdited
. Note that there is a potential little wriggle. If you're not careful, you change the model, it then changes the widget, and then that re-raises the "changed" signal and you get stuck forever. My slot reads the current value from the model and exits if the value passed to the slot is the same as that retrieved from the model. I also useQt::QueuedConnection
to prevent the slot causing changes while still within the original signal call, which was a problem. These may be because I am usingQSpinBox
es, may not apply when usingQLineEdit::textEdited
(which is a different signal fromQLineEdit::textChanged
which will be emitted when you change the value in the model programmatically and it reflects back to the widget).