[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] Small question about QLocale.toString vs locale.format
From:       Elvis Stansvik <elvstone () gmail ! com>
Date:       2016-02-11 9:58:18
Message-ID: CAHms=eYmEYgQ1mtWkhyGKPXZEVQVwopaWzt9NRh36cvvLQUEOQ () mail ! gmail ! com
[Download RAW message or body]

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
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic