QSpinBox thousand separator

旧巷老猫 提交于 2019-12-06 07:43:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!