问题
With a QSpinBox is it possible to display the thousand separator of a number while user enter it like 10,000 Which is the best way to do that ?
回答1:
You could subclass QSpinBox
and reimplement the textFromValue which is responsible for the display of the value to the spinbox widget. A possible implementation could be the following:
QString MySpinBox::textFromValue(int value)
{
return this->locale()->toString(value);
}
Using locale is the best way since it will display the separator based on the user's settings.
回答2:
i know this is late but this may help other people. i used this to update the thousand separator
ui->doubleSpinBox->setGroupSeparatorShown(true);
or
set the property it in the form ui
In my QDialog Form i used this to update the amount with thousand separator,
void DialogCashPayment::on_doubleSpinBox_valueChanged(double arg1){
ui->doubleSpinBox->setValue(arg1);
}
EDIT:
Found a bug when amount is 10k above, the cursor position is changed. i don't know how to fix this yet. Maybe someone could fix this.
来源:https://stackoverflow.com/questions/9274884/qspinbox-thousand-separator