[Qt-interest] How to get DoubleSpinBox to display null value using QDataWidgetMapper
Andre Somers
andre at familiesomers.nl
Wed Jan 20 10:32:52 CET 2010
bar tomas wrote:
> Hi,
>
> I'm using QDataWidgetMapper to create a form-like interface to a database table.
> I've mapped a DoubleSpinBox to a float field in my table.
> However, even when this field contains a null value in my database,
> the DoubleSpinBox displays the value 0.00.
> I would like the DoubleSpinBox to display blank when the value is null
> in the database.
> What would be the simplest way to do this?
>
You could try to subclass QDoubleSpinBox and give it it's own value()
property that takes a QVariant. I think you'll have to make it the USER
property. Then, in you implementation of setValue, first call
QDoubleSpinBox::setValue(newValue::toDouble()), and then if the
newValue.isValid() is false, call lineEdit()->setText("").
Something like that should do the trick, but I did not try it myself.
The basic problem is, that toDouble() on a QVariant that is invalid,
will return a default-constructed value that is valid. 0.0 to be exact.
André
More information about the Qt-interest-old
mailing list