Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

This funny decimal point...



  • I use QLineEdit to enter some floating point values. To restrict input I set the validator:

    QDoubleValidator* realvalidator;
    realvalidator = new QDoubleValidator(0.0, 1000000.0, 2, this);
    realvalidator->setNotation(QDoubleValidator::StandardNotation);
    ui->lineEdit->setValidator( realvalidator );
    

    as obvious. To show Android digital keyboard I use input method hint:

    ui->lineEdit->setInputMethodHints( Qt::ImhFormattedNumbersOnly );
    

    This shows virtual digital keyboard with button "." for decimal point. But it... does not work cause in my locale the decimal point is ",". Validator ignores this button. Ok, I remove last code line. This forces show alpha-numeric keyboard with "," button. It enters to line and line looks fine... But when I convert data to double value with

    ui->lineEdit->text().toDouble()
    

    I get 0.0 cause "," is not recognizable by toDouble() conversion - this conversion ignores locale. I had write before toDouble() this stupid line to get all temporarily working:

    ui->lineEdit->setText(ui->lineEdit->text().replace(QChar(','),QChar('.')));
    

    This rocks. But now I have TWO decimal points! One for editor and another one for storage. What's a fun... I would limit this only by "." to allow use digital keyboard and convert without stupid code. I tried use

    realvalidator->setLocale(QLocale(QLocale::Arabic));
    

    but this... prohibits input both "," and ".".
    :-()

    Any ideas?


  • Lifetime Qt Champion

    @Gourmet

    ui->lineEdit->text().toDouble()

    Try QLocale::toDouble() instead.

    Regards



  • @aha_1980 said in This funny decimal point...:

    Try QLocale::toDouble() instead.

    Oh, my... This is not even a static function...

    But what if I want show digital keyboard with "." button?


  • Lifetime Qt Champion

    @Gourmet said in This funny decimal point...:

    @aha_1980 said in This funny decimal point...:

    Try QLocale::toDouble() instead.

    Oh, my... This is not even a static function...

    Yeah, but it works :)

    But what if I want show digital keyboard with "." button?

    Sorry, out of scope for me



  • @aha_1980 said in This funny decimal point...:

    Yeah, but it works :)

    Yeah! But it CREATES TWO DECIMAL POINTS TOO!!! Other app part uses QML to draw values in ListView.

    text: modelData.Value
    

    In it the "." appears again!


  • Lifetime Qt Champion

    Hi,

    Out of curiosity, why not use a QDoubleSpinBox ?



  • @SGaist said in This funny decimal point...:

    Hi,
    Out of curiosity, why not use a QDoubleSpinBox ?

    Did you try use standard Qt controls on Android screen? They are useless. The standard spin box is VERY uncomfortable on small smartphone screen. Therefore I will need write my own decorated spinbox with large buttons. This is not needed and time wasting. And I am not sure if QDoubleSpinBox won't show virtual digital keyboard with "." and... ignore this button.

    For me it would be absolutely enough allow enter "." in QLineEdit with real validator. And not only for me. In my country about 80% people use "." for decimal point. Everywhere. I do not know who invented ","... This was stupid solution.


  • Lifetime Qt Champion

    @Gourmet said in This funny decimal point...:

    Did you try use standard Qt controls on Android screen? They are useless. The standard spin box is VERY uncomfortable on small smartphone screen. Therefore I will need write my own decorated spinbox with large buttons. This is not needed and time wasting. And I am not sure if QDoubleSpinBox won't show virtual digital keyboard with "." and... ignore this button.

    I overlooked the Android part. Did you consider using QtQuick.Controls ? They might suite your needs better and allow you to get your GUI working on Android faster.

    @Gourmet said in This funny decimal point...:

    For me it would be absolutely enough allow enter "." in QLineEdit with real validator. And not only for me. In my country about 80% people use "." for decimal point. Everywhere. I do not know who invented ","... This was stupid solution.

    Locales existed way before computers were even the glimpse of an idea.



  • @SGaist said in This funny decimal point...:

    Did you consider using QtQuick.Controls ?

    I use QtQuick for other interface part - for scrolling history list of this line edit. But this list build logic is little complex and is not suitable for QML. Or better say - on C++ it is implemented easier. I confess following religion - QML/QtQuick only for views, but Qt/C++ for models and business logic. Therefore QLineEdit is most suitable solution. It works fine. But how force validator pass "." instead of "," in this edit only?


  • Moderators

    @Gourmet said in This funny decimal point...:

    I tried use

    realvalidator->setLocale(QLocale(QLocale::Arabic));
    

    but this... prohibits input both "," and "."

    This sounds very strange.

    Does this also happen on your development computer? Or does it only happen on your Android device?



  • @JKSH said in This funny decimal point...:

    Does this also happen on your development computer? Or does it only happen on your Android device?

    The same behavior is on Android and Linux Kubuntu development station. Probably this should be done by some other manner. But I do not see docs or examples.



  • @JKSH said in This funny decimal point...:

    realvalidator->setLocale(QLocale(QLocale::Arabic));

    realvalidator->setLocale(QLocale(QLocale::English));
    

    works with ".". Do Arabic numbers not include decimal points?...


  • Moderators

    @Gourmet
    google says, Arabic decimal point is U+066B whereas the rest of the world uses U+2396 and they have a different separator for thousands

    https://en.wikipedia.org/wiki/Decimal_separator#Other_numeral_systems


Log in to reply