Results 1 to 14 of 14

Thread: qdoublespinbox with scientific notation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qdoublespinbox with scientific notation

    I think this is a wrong approach. Instead of fighting with the decimals, you should aim at converting the visual output of the spinbox to scientific notation and vice versa. Maybe you can leave the internal representation as it is now.

  2. #2
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qdoublespinbox with scientific notation

    Quote Originally Posted by wysota View Post
    I think this is a wrong approach. Instead of fighting with the decimals, you should aim at converting the visual output of the spinbox to scientific notation and vice versa. Maybe you can leave the internal representation as it is now.
    I have also thougth of that, but it is not possible. If I set the internal decimals to lets say 1000, then at the round function it will nevertheless be rounded to the maximum of decimals of a double. So at 1e-34 which is very likely more digits than a double without exponential can represent if will be rounded to 0. (Not tested, just my interpretation of the code)

    Matthias

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

    Default Re: qdoublespinbox with scientific notation

    Even if you use the scientific notation internally this is represented as a double so the precision will be limited nevertheless. So here it doesn't matter.

  4. #4
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qdoublespinbox with scientific notation

    I have now a working solution. However the code amount is about 600 LOC.

    This widget is derived from QDoubleSpinBox. It uses a decimal value of 1000 (that is more decimal points than a double can handle) and implements a new decimal value for the presentation in scientific notation. The Validator is realised by setting the LineEdit to a QDoubleValidator::ScientificNotation. However the most important part is the reimplementation of textFromValue and valueFromText. This unfortunately requires to copy the whole validation code of QDoubleSpinBox, which can not be borrowed and represents the major part of the code.

    Since I can not paste the whole code I put it online at:
    http://www.matthiaspospiech.de/blog/...ific-notation/

    Can this code be shrinked by keeping the functionality?

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
  •  
Qt is a trademark of The Qt Company.