I am developing a desktop application using pyside(qt), I want to access(iterate) all line edit components of QWidget. In qt I found two methods findChild and findChildren but there is no proper example found and My code shows error, ‘form’ object has no attribute ‘findChild’.
Here ‘form’ is Qwidget form consist components lineEdit, comboboxes, Qpushbuttons etc.
Code:
lineEdits = form.findChild<QLineEdit>() //This is not working
lineEdits = form.findChild('QLineEdit) //This also not working
The signatures of
findChildandfindChildrenare different in PySide/PyQt4 because there is no real equivalent to the C++ cast syntax in Python.Instead, you have to pass a type (or
tupleof types) as the first argument, and an optional string as the second argument (for matching theobjectName).So your example should look something like this:
Note that
findChildandfindChildrenare methods ofQObject– so if your form does not have them, it cannot be aQWidget(because all widgets inheritQObject).