Question

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.

Was it helpful?

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top