[Qt-interest] Locale input/output of custom doubleSpinbox Delegate

Ben Swerts benswerts at telenet.be
Thu Aug 27 19:38:34 CEST 2009


Hi Matthias,

You can do this using QLocale.
* When the data() function of your model is called with role ==
Qt::EditRole, just return a QVariant( double )
* When the data() function of your model is called with role ==
Qt::DisplayRole, return QVariant( QLocale::system()->toString( double ) )

If you want to convert a QString with a value in the locale, you can use
QLocale::system()->toDouble( QString ).

Hope it helps.
Greets,


	Ben

> I created a class DoubleSpinBoxDelegate which is simply a delegate using
> a QDoubleSpinBox.
> 
> Now if I insert data into a tableview table, it is in english format
> "10.123",
> If I edit it the result is returned in locale (german): "10,123".
> 
> So I thought to insert the values in the table directly in german format.
> If I then edit the value is returns 0 as a value in case there was a dot
> and a comma as in "40.000,123".
> 
> How can I solve this problem?
> 
> Matthias




More information about the Qt-interest-old mailing list