PDA

View Full Version : help with.. numeric mask....



ocascante
12th July 2007, 02:01
Hi,

Somebody have any idea about how to mask number in qlinedit, i did check the qt mask but i need something different.
In a qlineedit field, the user input 9349894.00 and i need to show this like 9,349,894.00 after the user move to the next field.
Thanks for anybody who wants to answer this question and help!!

jpn
12th July 2007, 10:53
I'm afraid this is not possible to do within designer unless you're happy with setting an input mask. In code, you could catch focus out event and and apply a localized number when appropriate, for example like this:


// MyLineEdit inherits QLineEdit and reimplements QWidget::focusOutEvent()
void MyLineEdit::focusOutEvent(QFocusEvent* event)
{
QLineEdit::focusOutEvent(event);

bool ok = false;
double real = text().toDouble(&ok);
if (ok)
setText(QLocale(QLocale::English).toString(real, 'f', 2));
}