Qasim
Qasim

Reputation: 83

How to display 300000 as 300,000 in a QT spinbox and label?

I have a number that is displayed in a QSpinBox and QLabel like this:

3570000

But I want it to look like this:

3,570,000

How must I do it?

Upvotes: 1

Views: 204

Answers (2)

mascoj
mascoj

Reputation: 1329

Your best bet would be to create your own subclass of QSpinBox and override the valueFromText and textFromValue functions. See Subclassing QSpinBox for more info.

Upvotes: 1

goug
goug

Reputation: 2444

Since Qt 5.3 this is a feature supported by QAbstractSpinBox, from which QSpinBoxis derived, which defaults to false. Just call

QSpinBox::setGroupSeparatorShown(true);`

after you've created the QSpinBox.

If you are using a version of Qt prior to Qt 5.3, then subclassing is the only choice.

Upvotes: 5

Related Questions