2012-01-22 3 views
2
나는 두 열이

QTreeWidget에서, 하나의 열은 '의 URL을리스트'를 나타내는 반복 번째는 ' 결과'를 나타낸다. 첫 번째 열에 url 목록을로드했습니다. 이제이 목록을 반복하고 두 번째 열의 텍스트를 변경하는 반복을 원합니다. 이것을 달성하는 방법?PyQt는 QTreeWidget는

+0

는 당신이 우리의 코드 제시해주십시오 수 있습니다 : 나는 self.treeWidget을 가정하고

root = self.treeWidget.invisibleRootItem() child_count = root.childCount() for i in range(child_count): item = root.child(i) url = item.text(0) # text at first (0) column item.setText(1, 'result from %s' % url) # update result column (1) 

는에 의해 채워집니다? – aayoubi

+1

두 개의 열만있는 경우'QTreeWidget'을'QTableWidget'으로 바꿀 수 있습니다. – reclosedev

답변

6

QTreeWidget.invisibleRootItem()을 호출하여 루트 항목을받은 다음 QTreeWidgetItem API를 사용하여 항목을 반복 할 수 있습니다.

예 :

self.treeWidget.setColumnCount(2) # two columns, url result 
for i in range(10): 
    self.treeWidget.insertTopLevelItem(i, QTreeWidgetItem(QStringList('url %s' % i))) 
+0

고마워요. 내가 알고 싶었던 것입니다 :) – Nuncjo