Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved]how to use QDoubleValidator?
Forum Updated to NodeBB v4.3 + New Features

[Solved]how to use QDoubleValidator?

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 3 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dreamerindia
    wrote on last edited by
    #1

    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]

    ~Ravivarman~

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      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.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dreamerindia
        wrote on last edited by
        #3

        Sorry for delay reply...

        Can we control value in QLabel?

        ~Ravivarman~

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jake007
          wrote on last edited by
          #4

          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


          Code is poetry

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved