Set QLineEdit to accept only numbers

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

    If you're using QT Creator 5.6 you can do that like this:

    #include 
    
    ui->myLineEditName->setValidator( new QIntValidator);
    

    I recomend you put that line after ui->setupUi(this);

    I hope this helps.

提交回复
热议问题