Set QLineEdit to accept only numbers

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

    The best is QSpinBox.

    And for a double value use QDoubleSpinBox.

    QSpinBox myInt;
    myInt.setMinimum(-5);
    myInt.setMaximum(5);
    myInt.setSingleStep(1);// Will increment the current value with 1 (if you use up arrow key) (if you use down arrow key => -1)
    myInt.setValue(2);// Default/begining value
    myInt.value();// Get the current value
    //connect(&myInt, SIGNAL(valueChanged(int)), this, SLOT(myValueChanged(int)));
    

提交回复
热议问题