Search code examples
pythonqtpyqtqlineedit

PyQt Collection of QLineEdit objects


Is there some way in PyQt to get a collection of all QLineEdit objects?

I am trying to add a reset button that will blank out all text in all QLineEdit on a form, so I am looking for a way to loop through all QLineEdit objects rather than listing them all in my reset function that will connect to the reset button.

Thank you.


Solution

  • If all the line-edits have a parent, you could use:

    for child in parent.findChildren(QtGui.QLineEdit):
        child.clear()
    

    Or possibly:

    for widget in qApp.allWidgets():
        if isinstance(widget, QtGui.QLineEdit):
            widget.clear()