[Qt-interest] How to make QSpinBox display thousands separators?
K. Frank
kfrank29.c at gmail.com
Tue Mar 23 04:44:20 CET 2010
Hello List -
I would like to have my QSpinBox format numbers with the thousands (group)
separator (for me, ','). I.e., I would like "11,222,333" to be
displayed, rather
than "11222333".
The documentation suggests that by default QSpinBox will display the thousands
separator:
QString QSpinBox::textFromValue ( int value ) const [virtual protected]
This virtual function is used by the spin box whenever it needs to
display the given value.
The default implementation returns a string containing value
printed in the standard way
using QWidget::locale().toString().
(Indeed, qSpinBox->locale().toString (10000) returns "10,000", with
the separator.)
(Note, the documentation for QDoubleSpinBox::textFromValue ( double
value ) states
explicitly that it "will remove the thousand separator." In this --
according to the
documentation -- QDoubleSpinBox differs from QSpinBox.)
I imagine that I could put the thousands separators back in by
deriving from QSpinBox
and overriding textFromValue. But, based on the documentation, I
expect to get the
thousands separators by default, so I'm worried that I've merely
overlooked some setting.
This is with Qt 4.6.1 built on windows with TDM-2 mingw32 4.4.1.
Thanks.
K. Frank
More information about the Qt-interest-old
mailing list