How to get all child components of QWidget in pyside/pyqt/qt?

假装没事ソ 提交于 2019-11-30 09:07:48

The signatures of findChild and findChildren are 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 tuple of types) as the first argument, and an optional string as the second argument (for matching the objectName).

So your example should look something like this:

lineEdits = form.findChildren(QtGui.QLineEdit)

Note that findChild and findChildren are methods of QObject - so if your form does not have them, it cannot be a QWidget (because all widgets inherit QObject).

Use this method QObject::findChildren(onst QString & name = QString()) with no parameters.

Omitting the name argument causes all object names to be matched.

Here is C++ example code:

QList<QLineEdit*> line_edits = form.findChildren<QLineEdit*>();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!