Guillaume Paris
Guillaume Paris

Reputation: 10519

QLineEdit thousand separator

With a QLineEdit is it possible to display the thousand separator of a number while user enter it

Which is the best way to do that ?

Upvotes: 3

Views: 1603

Answers (1)

Thomas Vincent
Thomas Vincent

Reputation: 2224

You can connect a slot to the void QLineEdit::textEdited ( const QString & text ) signal of your QLineEdit and add some space/separator in the edited string via the setText() method. It should work since textEdit won't be emit-ed again.

The Qt doc says :

Unlike textChanged(), this signal (textEdited) is not emitted when the text is changed programmatically, for example, by calling setText().

You can take advantage of this situation to check if the string entered by the user is actually a number and correct it if needed.

Upvotes: 3

Related Questions