PDA

View Full Version : QLineEdit automatic money format.



wirasto
30th October 2009, 15:49
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.


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);
}


Need your help and sorry about my english :)

wysota
31st October 2009, 07:24
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.