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. QRegExp assigning a value based on a condition
Forum Updated to NodeBB v4.3 + New Features

QRegExp assigning a value based on a condition

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 312 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.
  • NevezN Offline
    NevezN Offline
    Nevez
    wrote on last edited by
    #1

    hi, I want to create my own dateEdit using QLineEdit. So far I've created a QRegExp. It's getting close to what I want, but I haven't quite caught it yet. I want the program to put a period automatically after the Day and Month parts are entered. How can I update this? Here is the current code ;

    QRegularExpression  rx4("[0-9]{0,2}[.][0-9]{0,2}[.][0-9]{0,4}");
    QValidator *validator = new QRegularExpressionValidator(rx5, this);
    ui->lineEdit->setValidator(validator);
    
    JonBJ 1 Reply Last reply
    0
    • NevezN Nevez

      hi, I want to create my own dateEdit using QLineEdit. So far I've created a QRegExp. It's getting close to what I want, but I haven't quite caught it yet. I want the program to put a period automatically after the Day and Month parts are entered. How can I update this? Here is the current code ;

      QRegularExpression  rx4("[0-9]{0,2}[.][0-9]{0,2}[.][0-9]{0,4}");
      QValidator *validator = new QRegularExpressionValidator(rx5, this);
      ui->lineEdit->setValidator(validator);
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Nevez
      Validators only check what is in a field, they cannot alter it. If you want to do that you need to do something like write code on QLineEdit::textEdited() signal, or subclass QLineEdit.

      1 Reply Last reply
      0
      • NevezN Offline
        NevezN Offline
        Nevez
        wrote on last edited by
        #3

        So how do I get the numbers to be in a certain range with qexpreg?
        example: only numbers 1 to 30 should be entered

        JonBJ 1 Reply Last reply
        0
        • NevezN Nevez

          So how do I get the numbers to be in a certain range with qexpreg?
          example: only numbers 1 to 30 should be entered

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Nevez
          That is a quite different question from your original. You could do this with regular expressions, but it's not ideal. I think https://stackoverflow.com/questions/53611816/input-mask-and-validator-for-date-in-qlineedit?rq=1 does something like this. Better is integer validators, and for what you want custom code in the validation.

          Why you are wanting to reinvent the wheel for "my own dateEdit using QLineEdit" I do not know when Qt has a QDateEdit widget, optionally with a popup calender for the user. The whole job is done for you, including the parsing and returning of the date.

          1 Reply Last reply
          2
          • NevezN Offline
            NevezN Offline
            Nevez
            wrote on last edited by
            #5

            yes, this link gave me an idea on how to do the conditional and I tried it and it worked. Thanks

            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