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.
Code:
: QDialog(parent
), ui
(new Ui
::Dialog) {
ui->setupUi(this);
ui->lineEdit->setValidator(i);
ui->lineEdit->installEventFilter(this);
}
Dialog::~Dialog()
{
delete ui;
}
{
if (obj == ui->lineEdit) {
if (event
->type
() == QEvent::KeyPress) { QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
if (keyEvent->key()==46) return true;
}
}
// pass the event on to the parent class
return QDialog::eventFilter(obj, event
);
}
Need your help and sorry about my english :)
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.