QLineEdit with QDoubleValidator not emitting editingFinished() when e.g. 1,2 insted of 1.2 is entered
-
Hello,
Title says it all. I've got a QLineEdit with a QDoubleValidator:my_lineedit->setValidator(new QDoubleValidator(-DOUBLE_INF, DOUBLE_INF, 10, my_lineedit));
Now when I enter a number with a point ( . ) as decimal point editing finished is emitted and everything works fine.
However if I enter a comma ( , ) as decimal point the value seems to get accepted. but editing finished is not emitted.
Why is that. The behavior I want is that the user can enter either a comma or point as they like. -
Hello,
Title says it all. I've got a QLineEdit with a QDoubleValidator:my_lineedit->setValidator(new QDoubleValidator(-DOUBLE_INF, DOUBLE_INF, 10, my_lineedit));
Now when I enter a number with a point ( . ) as decimal point editing finished is emitted and everything works fine.
However if I enter a comma ( , ) as decimal point the value seems to get accepted. but editing finished is not emitted.
Why is that. The behavior I want is that the user can enter either a comma or point as they like.@gde23 said in QLineEdit with QDoubleValidator not emitting editingFinished() when e.g. 1,2 insted of 1.2 is entered:
Why is that.
Because comma is not a decimal point, it's a thousand-separator, in your locale.
1.2
is a full floating point number,1,2
is not.The behavior I want is that the user can enter either a comma or point as they like.
I don't think Qt offers "alternatives" for decimal point in a locale --- unless someone knows of one which does.
See https://forum.qt.io/topic/67850/disable-comma-in-qdoublevalidator for thoughts.
- As @SGaist says there, why are you using a
QLineEdit
to enter a number when there is aQDoubleSpinBox
for floating point number entry and handling text<->number conversions? See also https://stackoverflow.com/questions/42534378/c-qt-creator-how-to-have-dot-and-comma-as-decimal-separator-on-a-qdoubles. - You could combine aspects of each of the answers there. E.g. maybe you want
QLocale::setNumberOptions(QLocale::RejectGroupSeparator)
, maybe you want to either reject,
or perhaps change it to.
. Or try a conversion in two locales, one of which accepts comma as decimal point and another with accepts dot/period.
- As @SGaist says there, why are you using a
-
Hello,
Title says it all. I've got a QLineEdit with a QDoubleValidator:my_lineedit->setValidator(new QDoubleValidator(-DOUBLE_INF, DOUBLE_INF, 10, my_lineedit));
Now when I enter a number with a point ( . ) as decimal point editing finished is emitted and everything works fine.
However if I enter a comma ( , ) as decimal point the value seems to get accepted. but editing finished is not emitted.
Why is that. The behavior I want is that the user can enter either a comma or point as they like.My only thought about this is building your own
QDoubleValidator
subclass and handle the validation yourself, by using two different locale versions. One that uses comma and one with a dot.
Don't know if that works.