Results 1 to 3 of 3

Thread: QDoubleValidator and setDecimals

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QDoubleValidator and setDecimals

    Why this code not work:

    Qt Code:
    1. qv->setDecimals(2);
    2. editor->setValidator(qv);
    To copy to clipboard, switch view to plain text mode 

    The number takes all decimals, not only 2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDoubleValidator and setDecimals

    Quote Originally Posted by zorro68 View Post
    The number takes all decimals, not only 2
    Because you can enter also: 1.234567e4.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDoubleValidator and setDecimals

    Use a reg exp validator with a regexp set to "\d*\.\d{1,2}" instead if you want to disallow the scientific notation. Remember about escaping backslashes.

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.