[PyQt] Qstring %L omit thousand separator

Samuele Carcagno sam.carcagno at gmail.com
Mon Jun 14 17:32:07 BST 2010


Hi,

I would like to convert a number to a localized string without the thousands separator,
I set the numberOptions to omit the group separator. This seems to work with the 
locale.toString() function, but not with the QString('%L1').arg() syntax.
I'm attaching a short example below. Do you know why this happens?
Am I missing something to make it work with the  QString('%L1').arg() syntax?

I am on Python 2.6.5 - Qt 4.6.2 - PyQt 4.7.2 on Kubuntu Lucid


#Example
from PyQt4.QtCore import*
from PyQt4.QtGui import*

thisLoc = QLocale(QLocale.English, QLocale.UnitedKingdom)
thisLoc.setNumberOptions(thisLoc.OmitGroupSeparator | thisLoc.RejectGroupSeparator)
QLocale.setDefault(thisLoc)
print(thisLoc.toString(12345.6))
#12345.6 this works correctly
print(QString("%L1").arg(12345.6))
# 12,345.6 this doesn't work

Cheers,

Sam


More information about the PyQt mailing list