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.
: 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
);
}
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog)
{
ui->setupUi(this);
QRegExp rx("[1-9][\\d*|.]*");
QValidator *i = new QRegExpValidator(rx, this);
ui->lineEdit->setValidator(i);
ui->lineEdit->installEventFilter(this);
}
Dialog::~Dialog()
{
delete ui;
}
bool Dialog::eventFilter(QObject *obj, QEvent *event)
{
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);
}
To copy to clipboard, switch view to plain text mode
Need your help and sorry about my english
Bookmarks