Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个QSpinBox并且我希望它只接受正的自然数。这工作正常,直到我输入一个点.
QSpinBox
.
如果我输入234235.23456并将焦点更改为其他旋转框,则值将更改为23423523456.
234235.23456
23423523456
所以我正在寻找一种方法来忽略背后的一切.
如果没有子类化,这可能QSpinBox吗?
我找到了解决问题的方法:
QDoubleSpinBox * box = new QDoubleSpinBox(); box->setDecimals(0); box->setSingleStep(1.0); box->findChild<QLineEdit*>()->setValidator(new QRegExpValidator(QRegExp(QString("^[1-9][0-9]*$"))));