QLineEdit 只能输入数字检验方法

void QLineEdit::setValidator(const QValidator *v)
Sets this line edit to only accept input that the validator, v, will accept. This allows you to place any arbitrary constraints on the text which may be entered.
If v == 0, setValidator() removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to maxLength()).

这个说明就使用setValidator进行QLineEdit的设置,使对象只能接受QValidator 对象规定的方式录入。
如果我们使QLineEdit只能录入数字,则进行以下设置:

QLineEdit* pEdit = new QLineEdit(this);
pEdit->setValidator(new QValidator (0,100,this));

你可能感兴趣的:(QT学习)