View Full Version : QDoubleSpinBox: dot as comma
Raccoon29
20th May 2008, 15:21
Hi everyone,
is there a way to put decimal comma by pressing numeric keypad dot?
Es.
123,45 -> 123 then pressing "." it puts the "," for 123,45
now with "." simply does nothing...
I searched around but I didn't find anything
Thanks in advance!
mcosta
21st May 2008, 08:06
The decimal point character depends to QLocale set for the Widget with QWidget::setLocale()
For "Italian" locale this is ','; for "C" locale is ".".
You can override this behaviour deriving from QDoubleSpinBox and reimplementing QWidget::keyPressEvent()
QDoubleSpinBox::textFromValue()
QDoubleSpinBox::valueFromText()
Raccoon29
21st May 2008, 16:52
From doc:
(QDoubleSpinBox::textFromValue()): [...]The default implementation returns a string containing value printed using QLocale().toString(value, QLatin1Char('f'), decimals()) and will remove the thousand separator.[...]
so to have the thousand separator? (sorry, I can't understand this section... :confused: )
QLocale formats numbers so that it includes a thousand separator. QDoubleSpinBox just removes it because it's not sensible to include in a spin box...
Anyway, what I meant was something like this:
QString MyDoubleSpinBox::textFromValue(double value) const
{
QString text = QDoubleSpinBox::textFromValue(value);
return text.replace(QLocale().decimalPoint(), QLatin1Char('.'));
}
double MyDoubleSpinBox::valueFromText(const QString& text) const
{
return QDoubleSpinBox(QString(text).replace(QLatin1Char(' .'), QLocale().decimalPoint()));
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.