Results 1 to 2 of 2

Thread: QLineEdit automatic money format.

  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Qt products
    Platforms
    Unix/X11 Windows
    Thanks
    20
    Thanked 5 Times in 5 Posts

    Question QLineEdit automatic money format.

    How to make QLineEdit set display data to money format ? Like, if user type 1000000 then QLineEdit text display autochange to 1.000.000. Of course, the Qlineedit just allow number type. Other character will deny, included . (dot) character.

    So far, I use QRegExpValidator for validating user input. And use eventFilter for reject . (dot) character.
    But, I don't know how to autochange text display in QLineEdit to money format.

    This code who I use.
    Qt Code:
    1. Dialog::Dialog(QWidget *parent)
    2. : QDialog(parent), ui(new Ui::Dialog)
    3. {
    4. ui->setupUi(this);
    5.  
    6. QRegExp rx("[1-9][\\d*|.]*");
    7. QValidator *i = new QRegExpValidator(rx, this);
    8. ui->lineEdit->setValidator(i);
    9.  
    10. ui->lineEdit->installEventFilter(this);
    11. }
    12.  
    13. Dialog::~Dialog()
    14. {
    15. delete ui;
    16. }
    17.  
    18. bool Dialog::eventFilter(QObject *obj, QEvent *event)
    19. {
    20. if (obj == ui->lineEdit) {
    21. if (event->type() == QEvent::KeyPress) {
    22. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    23. if (keyEvent->key()==46) return true;
    24. }
    25. }
    26. // pass the event on to the parent class
    27. return QDialog::eventFilter(obj, event);
    28. }
    To copy to clipboard, switch view to plain text mode 

    Need your help and sorry about my english

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

    Default Re: QLineEdit automatic money format.

    The regexp is wrong. It says "a non-zero digit followed by any number of digits or any other characters". I doubt that's what you wanted.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Money Format
    By newermind in forum Qt Programming
    Replies: 3
    Last Post: 19th May 2009, 15:34
  2. QLineEdit with money format
    By haldrik in forum Qt Programming
    Replies: 10
    Last Post: 12th September 2008, 17:34
  3. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 16:13
  4. Replies: 2
    Last Post: 20th March 2008, 15:37
  5. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 17:48

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.