PDA

View Full Version : Format value slot



estanisgeyer
25th January 2008, 13:06
Good day,

I have a function that formats the decimal places. I created a slot that makes this format, but the problem is that we have to create a slot for each QLineEdit, how do I get around that? Below part of the code:



connect(ui.lineEdit_ProductValue, SIGNAL(lostFocus()), this, SLOT(formatValueProduct()))
connect(ui.lineEdit_PValue, SIGNAL(lostFocus()), this, SLOT(formatValueP()));

void Product::formatValueProduct()
{
ui.lineEdit_ProductValue->setText(customFormat(ui.lineEdit_ProductValue->text(), CURRENCY));
}


void Product::formatValueP()
{
ui.lineEdit_PValue->setText(customFormat(ui.lineEdit_PValue->text(), 3));
}



Thanks,

Marcelo E. Geyer

jpn
25th January 2008, 14:25
I would suggest using a validator, see QLineEdit::setValidator() for more details.

estanisgeyer
25th January 2008, 17:41
Thank you for your suggestion, but was not well what I needed. What we really want is to make the formatting when you lose focus. Currently, it is not entered a numeral, it automatically turns on double formatted (0.000 - or 0,000 in Brazilian Locate). To minimize some problems, I'm using connectSlotsByName.

Any suggestion will be considered.
thanks,

Marcelo E. Geyer

jpn
25th January 2008, 18:33
QValidator::fixup() is called when editing is finished and the input is "acceptable". Thus, you could simply make to .toUpper(). Notice that the input parameter is non-const.

wysota
25th January 2008, 18:55
Can't you use a QDoubleSpinBox with a suffix?