[PyQt] Small question about QLocale.toString vs locale.format
Elvis Stansvik
elvstone at gmail.com
Thu Feb 11 09:58:18 GMT 2016
In a custom item model + view of mine, I have an item that represents
a float value:
class FloatItem(CoreLogItem):
def __init__(self, value):
self._value = float(value)
def data(self):
return QLocale.system().toString(self._value, 'f', 2)
def setData(self, value):
try:
self._value = float(value)
except ValueError:
return False
return True
def editData(self):
return self._value
My model's data() and setData() delegate to the data()/setData() shown here.
My question is whether I should use QLocale.system().toString(..) to
format the float value in the data() method, or Python's own
locale.format, or if it doesn't really matter?
As you can see, I picked QLocale, as I know that the editing of my
item will be done using a QDoubleSpinBox, which will use the QLocale,
so there's less risk (however unlikely) that the presentation of my
number will be different from when it is edited.
Just thought I'd ask if there's something that speaks in favor of
using the Python locale module here instead?
Cheers,
Elvis
More information about the PyQt
mailing list