2012-02-22 223 views
7

我正在開發一個使用pyside(qt)的桌面應用程序,我想訪問(迭代)QWidget的所有行編輯組件。在qt中,我找到了兩種方法 findChild findChildren但沒有找到適當的示例,我的代碼顯示錯誤,'form'對象沒有屬性'findChild'。 這裏 '形式' 是QWidget的形式由組分lineEdit,組合框等等Qpushbuttons如何在pyside/pyqt/qt中獲取QWidget的所有子組件?

代碼:

lineEdits = form.findChild<QLineEdit>() //This is not working 

lineEdits = form.findChild('QLineEdit) //This also not working 

回答

16

findChildfindChildren的簽名是在PySide/PyQt4的不同,因爲沒有真正等效於在Python C++的轉換語法。

相反,您必須傳遞類型(或類型爲tuple)作爲第一個參數,並將可選字符串作爲第二個參數(用於匹配objectName)。

所以你的例子應該是這個樣子:

lineEdits = form.findChildren(QtGui.QLineEdit) 

注意findChildfindChildrenQObject方法 - 所以,如果你的表格沒有他們,就不可能是一個QWidget(因爲所有的構件都繼承QObject )。

+0

@ekhumoro你能幫我在這裏:http://stackoverflow.com/questions/25164853/how-to-use-findchildren#25165738 – Ejaz 2014-08-06 19:01:49

相關問題