문제

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 ?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top