3

I have a QSpinBox and I want it to only accept positive natural numbers. This works fine, until I enter a dot .

If I enter 234235.23456and change the focus to some other spinbox, the value is changed to 23423523456.

So I am looking for a way to ignore everything behind the .

Is this possible without subclassing QSpinBox?

Morix Dev
  • 2,700
  • 1
  • 28
  • 49
liquid.pizza
  • 505
  • 1
  • 10
  • 26

1 Answers1

2

I found a fix for my porblem:

QDoubleSpinBox * box = new QDoubleSpinBox();

box->setDecimals(0);
box->setSingleStep(1.0);

box->findChild<QLineEdit*>()->setValidator(new QRegExpValidator(QRegExp(QString("^[1-9][0-9]*$"))));
liquid.pizza
  • 505
  • 1
  • 10
  • 26