Set QLineEdit to accept only numbers

后端 未结 6 493
温柔的废话
温柔的废话 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:37

    You could also set an inputMask:

    QLineEdit.setInputMask("9")
    

    This allows the user to type only one digit ranging from 0 to 9. Use multiple 9's to allow the user to enter multiple numbers. See also the complete list of characters that can be used in an input mask.

    (My answer is in Python, but it should not be hard to transform it to C++)

提交回复
热议问题