Validate a Qlineedit to only take Double

Asked

Viewed 312 times

1

I’m using the QDoubleValidator data = new QDoubleValidator(0.00, 1000.00, 2, lineEdit);

However, when inserting the actual value in the lineEdit he does not resort to the point (.) as decimal and yes comma separator (,).

This causes problems when picking the entered value in the field because the program does not pick any value with number using commas.

How to solve this problem by leaving the point (.) as decimal separator?

1 answer

1

You need to define the locale of QDoubleValidator:

auto validator = new QDoubleValidator(0, 1000.00, 2, lineEdit);
validator->setLocale(QLocale("pt_BR"));
lineEdit->setValidator(validator);

Note that by default, Qt uses the system locale. If you use the above code to fix the locale, your program will no longer obey user preferences.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.