Search code examples
c++qtqspinbox

Making numbers in readable format in QSpinBox


I'm using QSpinBox for displaying and changing numbers. But numbers are large enough, it's hard to read them for user. Now I'm going to format numbers, for example if the number is 12345678 it should be displayed 12 345 678 or 12.345.678 like that. But I've no idea how to do that.

P.s: my english is not well, sorry for grammar mistakes.


Solution

  • Use this code to set QSpinBox separate thousand number:

      // Init
      ui->spinBox->setGroupSeparatorShown(true);
      ui->spinBox->setValue(123456);
      // Set value on change
      this->connect(ui->spinBox, &QSpinBox::valueChanged, [=] {
          ui->spinBox->setGroupSeparatorShown(true);
          ui->spinBox->setValue(ui->spinBox->value());
      });