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 lineEdit in application ?
Forum Updated to NodeBB v4.3 + New Features

How to set validator for all lineEdit in application ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 2.3k 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.
  • S Offline
    S Offline
    Sparkle24
    wrote on last edited by
    #1

    My application has 90 lineEdit widget. I want to set QDoubleValidator for every lineEdit.
    So how can I do that ? I can set individual I mean something like:
    @QLineEdit::setValidator(new QDoubleValidator(this)
    ui->lineEdit->setValidator(new QDoubleValidator(this))@
    But I want to set 90 lineEdits validator at once...

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      Hi,

      You can subclass QLineEdit and create your own custom lineEdit class, then set the validator inside your custom class and use it whereever its needed.

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        if you really have to do it at all at once and not as sam suggested you could do the following (for each widget without a parent):
        @
        foreach(QLineEdit* lineEdit, mainWindow.findChildren<QLineEdit*>() )
        lineEdit->setValidator(new QDoubleValidator(lineEdit));
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          If you only want to have doubles there, why not use "QDoubleSpinBox":http://qt-project.org/doc/qt-4.8/qdoublespinbox.html instead?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          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