Set QLineEdit to accept only numbers

后端 未结 6 492
温柔的废话
温柔的废话 2021-01-31 07:11

I have a QLineEdit where the user should input only numbers.

So is there a numbers-only setting for QLineEdit?

6条回答
  •  一个人的身影
    2021-01-31 07:26

    QLineEdit::setValidator(), for example:

    myLineEdit->setValidator( new QIntValidator(0, 100, this) );
    

    or

    myLineEdit->setValidator( new QDoubleValidator(0, 100, 2, this) );
    

    See: QIntValidator, QDoubleValidator, QLineEdit::setValidator

提交回复
热议问题