If you want your code to show properly formatted doubles no matter what locale, then you should do this:
class DoubleDelegate: public QStyledItemDelegate
{
Q_OBJECT
public:
DoubleDelegate
(QObject* parent
=0) : QStyledItemDelegate
(parent
) { } virtual ~DoubleDelegate() { }
{
return locale.toString( value.toDouble(), 'f', 2 );
}
return QStyledItemDelegate::displayText(value, locale);
}
};
class DoubleDelegate: public QStyledItemDelegate
{
Q_OBJECT
public:
DoubleDelegate(QObject* parent=0) : QStyledItemDelegate(parent) { }
virtual ~DoubleDelegate() { }
virtual QString displayText(const QVariant &value, const QLocale &locale) const
{
if (value.type() == QVariant::Double) {
return locale.toString( value.toDouble(), 'f', 2 );
}
return QStyledItemDelegate::displayText(value, locale);
}
};
To copy to clipboard, switch view to plain text mode
Your original code will substitute a comma for a period in all cases, regardless of locale. Maybe that's what you want to do, but an American will certainly be confused seeing a table where the entries are all of the form "123,45".
Bookmarks