Set QLineEdit to accept only numbers

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

    Why don't you use a QSpinBox for this purpose ? You can set the up/down buttons invisible with the following line of codes:

    // ...
    QSpinBox* spinBox = new QSpinBox( this );
    spinBox->setButtonSymbols( QAbstractSpinBox::NoButtons ); // After this it looks just like a QLineEdit.
    //...
    

提交回复
热议问题