[Qt-interest] How to get DoubleSpinBox to display null value using QDataWidgetMapper
bar tomas
bartomas at gmail.com
Wed Jan 20 12:04:55 CET 2010
Many thanks. I'll try your suggestion.
On Wed, Jan 20, 2010 at 9:32 AM, Andre Somers <andre at familiesomers.nl> wrote:
> 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é
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list