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. How to set validator for all Line edit
Forum Updated to NodeBB v4.3 + New Features

How to set validator for all Line edit

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 2.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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #2

    It is possible. What is possible is - Setting the validator is per object. You need to find the logic to set the validator for each&every lineEdit objects.

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    ManiRonM 1 Reply Last reply
    0
    • dheerendraD dheerendra

      It is possible. What is possible is - Setting the validator is per object. You need to find the logic to set the validator for each&every lineEdit objects.

      ManiRonM Offline
      ManiRonM Offline
      ManiRon
      wrote on last edited by
      #3

      @dheerendra

      can we set the validator for a individual group instead of setting for each and every line edit.

      Set Validator for all line edit in group which accepts only int values instead of setting for each and every line edit can we set validator for a all line edit at once so that it works.

      Set Validator for all line edit in group which accepts only string values .

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #4

        No nothing exist like this.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Hi,

          You can use findChildren and use a loop to set the validator.

          Also, you might want to consider using a more appropriate widget for integer input like QSpinBox.

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

          ManiRonM 3 Replies Last reply
          2
          • SGaistS SGaist

            Hi,

            You can use findChildren and use a loop to set the validator.

            Also, you might want to consider using a more appropriate widget for integer input like QSpinBox.

            ManiRonM Offline
            ManiRonM Offline
            ManiRon
            wrote on last edited by
            #6

            @SGaist

            I used something like this

            QList<QLineEdit *> allPButtons = this->findChildren<QLineEdit *>();
            for (int i=0; i < allPButtons.size(); i++)
            {
                allPButtons.at(i)->setValidator(new QIntValidator(0,20,this));
            }
            

            and it worked

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              You can use findChildren and use a loop to set the validator.

              Also, you might want to consider using a more appropriate widget for integer input like QSpinBox.

              ManiRonM Offline
              ManiRonM Offline
              ManiRon
              wrote on last edited by
              #7

              @SGaist

              But it applied for all the line edit. Now i have a three line edit in one group box and want to apply certain validator for them alone then whether is it possible? Just a doubt?

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                You can use findChildren and use a loop to set the validator.

                Also, you might want to consider using a more appropriate widget for integer input like QSpinBox.

                ManiRonM Offline
                ManiRonM Offline
                ManiRon
                wrote on last edited by
                #8

                @SGaist

                for group box i did something like this and it woked

                  QList<QLineEdit *> allPButtons = ui->groupBox- 
                                          >findChildren<QLineEdit *>();
                    for (int i=0; i < allPButtons.size(); i++)
                   {
                      allPButtons.at(i)->setValidator(new 
                    QIntValidator(0,20,this));
                    }
                
                1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #9

                  Yes, it possible if with little bit more programming. Set the object name for each of the lineEdit object. Inside the for loop just do something like.

                  for (int i=0; i < allPButtons.size(); i++)
                  {
                     if(allPButtons.at(i).objectName.compare("ManiRon")==0) {
                        // set validator
                     }else {
                      allPButtons.at(i)->setValidator(new QIntValidator(0,20,this));
                     }
                  }
                  

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  ManiRonM 1 Reply Last reply
                  2
                  • dheerendraD dheerendra

                    Yes, it possible if with little bit more programming. Set the object name for each of the lineEdit object. Inside the for loop just do something like.

                    for (int i=0; i < allPButtons.size(); i++)
                    {
                       if(allPButtons.at(i).objectName.compare("ManiRon")==0) {
                          // set validator
                       }else {
                        allPButtons.at(i)->setValidator(new QIntValidator(0,20,this));
                       }
                    }
                    
                    ManiRonM Offline
                    ManiRonM Offline
                    ManiRon
                    wrote on last edited by
                    #10

                    @dheerendra said in How to set validator for all Line edit:

                    if(allPButtons.at(i).objectName.compare("ManiRon")==0) {
                    // set validator
                    }else

                    it worked thanks sir

                    1 Reply Last reply
                    0
                    • dheerendraD Offline
                      dheerendraD Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on last edited by
                      #11

                      Cool. Enjoy Qt programming. Please move the issue to SOLVED state. It helps others as well.

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

                      1 Reply Last reply
                      1
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        One small thing:
                        @ManiRon said in How to set validator for all Line edit:

                        QList<QLineEdit *> allPButtons

                        Be more careful with the names of your variables. allPButtons suggests a list of QPushButton which is unrelated to your QLineEdit setup. This makes your code hard to read and understand.

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

                        ManiRonM 1 Reply Last reply
                        2
                        • SGaistS SGaist

                          One small thing:
                          @ManiRon said in How to set validator for all Line edit:

                          QList<QLineEdit *> allPButtons

                          Be more careful with the names of your variables. allPButtons suggests a list of QPushButton which is unrelated to your QLineEdit setup. This makes your code hard to read and understand.

                          ManiRonM Offline
                          ManiRonM Offline
                          ManiRon
                          wrote on last edited by
                          #13

                          @SGaist
                          sure Sir

                          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