How to set validator for all lineEdit in application ?



  • 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...



  • 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.


  • Moderators

    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));
    @



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.