Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]QRegExpValidator Questions
QtWS25 Last Chance

[Solved]QRegExpValidator Questions

Scheduled Pinned Locked Moved General and Desktop
qregexpvalidatoqregexp
4 Posts 2 Posters 1.9k Views
  • 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.
  • C Offline
    C Offline
    Corpse0327
    wrote on 29 Aug 2015, 20:28 last edited by Corpse0327
    #1

    Hi

    I have a QLineEdit and to prevent user from entering invalid entries i am using a QValidator. I have QLineEdits where only an integer can be entered and where a float can be entered.

    I found QDoubleValidator and QIntValidator but these had some features i didn't liked. For example user can enter dots to a QLineEdit with QIntValidator, which i don't want. Also user can enter dots and commas to a QLineEdit with QDoubleValidator.

    So i decided to use QRegExpValidator. For int validating i used

    validator = new QRegExpValidator(QRegExp("([-]{0,1})([0-9]{0,9})"));
    

    And for float validating

    validator = new QRegExpValidator(QRegExp("([-]{0,1})([0-9]{0,9})([.]{0,1}[0-9]{0,7})"));
    

    I have two questions regarding these

    1. Can i make it so user can not enter a number bigger or smaller than a value, like it does with QIntValidator?
    2. The line for float validating i created causes a problem. Currently user can enter fraction numbers without entering a dot first. How can i overcome this, so that user have to enter a dot before entering fraction numbers.

    Thanks in advance

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Aug 2015, 22:30 last edited by SGaist
      #2

      Hi,

      Why not use a QSpinBox and a QDoubleSpin box for the numerical inputs ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply 30 Aug 2015, 13:32
      1
      • S SGaist
        29 Aug 2015, 22:30

        Hi,

        Why not use a QSpinBox and a QDoubleSpin box for the numerical inputs ?

        C Offline
        C Offline
        Corpse0327
        wrote on 30 Aug 2015, 13:32 last edited by
        #3

        @SGaist Thank you very much, it really looks like what i was searching for. I will come back if any come across any problems :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 30 Aug 2015, 21:16 last edited by
          #4

          You're welcome !

          Sure thing

          Happy coding !

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          29 Aug 2015, 20:28

          • Login

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