1
給定一個PyQt4中的樹部件,有一些行和列:Qt treewidget python;迭代列
1)有沒有一種方法可以輕鬆地遍歷所有單元格?
2)如何檢查複選框是否與第一列分開檢查?
到目前爲止,我只設法獲得第一列中複選框的結果,請參閱here。
爲了澄清這裏是widget我怎麼想象它看起來像:(第四欄應該是可編輯)
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
def main():
app = QApplication (sys.argv)
tree = QTreeWidget()
item = QTreeWidgetItem()
tree.headerItem().setText(0, "col1")
tree.headerItem().setText(1, "col2")
tree.headerItem().setText(2, "col3")
tree.headerItem().setText(3, "Notes")
for ii in xrange(3):
parent = QTreeWidgetItem(tree)
parent.setText(0, "Parent {}".format(ii))
parent.setFlags(parent.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable)
for x in xrange(4):
child = QTreeWidgetItem(parent)
child.setFlags(child.flags() | Qt.ItemIsUserCheckable)
child.setText(0, "Child {}".format(x))
child.setCheckState(0, Qt.Unchecked)
#create the checkbox
for i in xrange(1, 5):
if i < 3:
child.setText(i, "")
child.setCheckState(i, Qt.Unchecked)
if i == 3:
child.setText(i, "Any Notes?")
child.setFlags(child.flags() | Qt.ItemIsEditable)
tree.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
沒有添加,真棒示例和解釋。 – Han88