Results 1 to 4 of 4

Thread: QSpinBox how to separate the numbers

  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default QSpinBox how to separate the numbers

    Dear All

    Could you please tell me how could we show the numbers that comes to QSpinBox, like

    999,999,999.00?

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

    Default Re: QSpinBox how to separate the numbers

    It's formatted according to current locale. I don't think one should force any specific formatting. However, if you insist, take a look at QSpinBox::textFromValue().
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: QSpinBox how to separate the numbers

    Dear jpn

    What I was asking was,

    you know in excel you write the number like 123456.12 and after you go to the other cell, number turns into 123,456.12. I was askin how could I make this auto for every spin?

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

    Default Re: QSpinBox how to separate the numbers

    Do you mean something like this?
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MyDoubleSpinBox : public QDoubleSpinBox
    4. {
    5. public:
    6. MyDoubleSpinBox(QWidget* parent = 0)
    7. : QDoubleSpinBox(parent) { }
    8.  
    9. void focusOutEvent(QFocusEvent* event)
    10. {
    11. QDoubleSpinBox::focusOutEvent(event);
    12. // force reformatting
    13. setValue(value());
    14. }
    15.  
    16. QString textFromValue(double value) const
    17. {
    18. // the default implementation removes group separator characters
    19. return QLocale(QLocale::English).toString(value, 'f', decimals());
    20. }
    21. };
    22.  
    23. int main(int argc, char *argv[])
    24. {
    25. QApplication a(argc, argv);
    26. MyDoubleSpinBox spinBox;
    27. spinBox.setRange(-999999, 999999);
    28. spinBox.setValue(500000);
    29. spinBox.show();
    30. return a.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. QSpinBox with checkbox
    By :db:sStrong in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2007, 14:22

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.