Results 1 to 5 of 5

Thread: Format value slot

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Format value slot

    Good day,

    I have a function that formats the decimal places. I created a slot that makes this format, but the problem is that we have to create a slot for each QLineEdit, how do I get around that? Below part of the code:

    Qt Code:
    1. connect(ui.lineEdit_ProductValue, SIGNAL(lostFocus()), this, SLOT(formatValueProduct()))
    2. connect(ui.lineEdit_PValue, SIGNAL(lostFocus()), this, SLOT(formatValueP()));
    3.  
    4. void Product::formatValueProduct()
    5. {
    6. ui.lineEdit_ProductValue->setText(customFormat(ui.lineEdit_ProductValue->text(), CURRENCY));
    7. }
    8.  
    9.  
    10. void Product::formatValueP()
    11. {
    12. ui.lineEdit_PValue->setText(customFormat(ui.lineEdit_PValue->text(), 3));
    13. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer

  2. #2
    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: Format value slot

    I would suggest using a validator, see QLineEdit::setValidator() for more details.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Format value slot

    Thank you for your suggestion, but was not well what I needed. What we really want is to make the formatting when you lose focus. Currently, it is not entered a numeral, it automatically turns on double formatted (0.000 - or 0,000 in Brazilian Locate). To minimize some problems, I'm using connectSlotsByName.

    Any suggestion will be considered.
    thanks,

    Marcelo E. Geyer

  4. #4
    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: Format value slot

    QValidator::fixup() is called when editing is finished and the input is "acceptable". Thus, you could simply make to .toUpper(). Notice that the input parameter is non-const.
    J-P Nurmi

  5. #5
    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: Format value slot

    Can't you use a QDoubleSpinBox with a suffix?

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  3. Replies: 2
    Last Post: 8th October 2007, 15:02
  4. Problem with slot
    By beerkg in forum Qt Programming
    Replies: 29
    Last Post: 3rd April 2007, 19:54
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.