[Solved]how to use QDoubleValidator?



  • Dear all,

    i'm trying to 4 1/2 digit display of the multimeter. it should only display between -19999 to +19999.
    I tried using QDoubleValidator as
    @ QDoubleValidator *validate=new QDoubleValidator(this);
    validate->setBottom(-19999);
    validate->setTop(19999);
    validate->setNotation(QDoubleValidator::StandardNotation);
    ui->lineEdit->setValidator(validate);@

    but it shows the range between -99999 to +99999

    also i tried

    @ QRegExp rx("[0-9]\d{0,4}");
    ui->lineEdit->setValidator(new QRegExpValidator (rx, this));@

    but it shows only between 0 to 99999.

    kindly anybody can solve it?

    [Edit: You only need an @ at the beginning and end of your code blocks, not every line. Cleaned up code -- mlong]


  • Moderators

    If I recall correctly, I believe that the validator will only check input typed at the keyboard. If you're trying to set the value through code, the validator won't stop you from doing so.

    I wouldn't recommend using a QLineEdit as a display-only widget, which it sounds like you're doing. Consider a QLabel.



  • Sorry for delay reply...

    Can we control value in QLabel?



  • It depends on how you mean value. You have setText() method in label class. You set number by doing so:
    @myLabel->setText(QString::number(value));@

    If you want value back to number, you only call:
    @myLabel->text().toDouble();@

    If you want to limit user input by value, you'll have to derive QValidator or QDoubleValidator, or you can use QDoubleSpinBox widget, which already has this built in.

    Regards,
    Jake


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.