Results 1 to 5 of 5

Thread: QDoubleSpinBox: dot as comma

  1. #1
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QDoubleSpinBox: dot as comma

    Hi everyone,

    is there a way to put decimal comma by pressing numeric keypad dot?
    Es.
    123,45 -> 123 then pressing "." it puts the "," for 123,45
    now with "." simply does nothing...

    I searched around but I didn't find anything
    Thanks in advance!
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDoubleSpinBox: dot as comma

    The decimal point character depends to QLocale set for the Widget with QWidget::setLocale()
    For "Italian" locale this is ','; for "C" locale is ".".

    You can override this behaviour deriving from QDoubleSpinBox and reimplementing QWidget::keyPressEvent()
    A camel can go 14 days without drink,
    I can't!!!

  3. The following user says thank you to mcosta for this useful post:

    Raccoon29 (21st May 2008)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDoubleSpinBox: dot as comma

    J-P Nurmi

  5. #4
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question Re: QDoubleSpinBox: dot as comma

    From doc:
    (QDoubleSpinBox::textFromValue()): [...]The default implementation returns a string containing value printed using QLocale().toString(value, QLatin1Char('f'), decimals()) and will remove the thousand separator.[...]
    so to have the thousand separator? (sorry, I can't understand this section... )
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDoubleSpinBox: dot as comma

    QLocale formats numbers so that it includes a thousand separator. QDoubleSpinBox just removes it because it's not sensible to include in a spin box...

    Anyway, what I meant was something like this:
    Qt Code:
    1. QString MyDoubleSpinBox::textFromValue(double value) const
    2. {
    3. QString text = QDoubleSpinBox::textFromValue(value);
    4. return text.replace(QLocale().decimalPoint(), QLatin1Char('.'));
    5. }
    6.  
    7. double MyDoubleSpinBox::valueFromText(const QString& text) const
    8. {
    9. return QDoubleSpinBox(QString(text).replace(QLatin1Char('.'), QLocale().decimalPoint()));
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    Raccoon29 (21st May 2008)

Similar Threads

  1. QDoubleSpinBox
    By coderbob in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2008, 11:30
  2. Validator for QDoubleSpinBox
    By ehamberg in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2008, 11:37
  3. Qt4.2.2 QDoubleSpinBox QSpinBox
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2007, 21:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.