我不明白为什么这似乎没有扩展 QTreeView 中的顶级根项目:
# clear existing treeview data
model = self.treeview.model().sourceModel()
model.clear()
# add treeview items here
# expand root level items
root = model.invisibleRootItem()
index = root.index()
for i in range(root.rowCount()):
item = model.indexFromItem(model.item(i,0))
self.treeview.expand(item)
self.treeview.setExpanded(item, True)
print 'expanded'
如果您使用代理模型,则必须使用它提供的索引,而不是源模型中的索引。所以要么这样做:
proxy = self.treeview.model()
for row in range(proxy.rowCount()):
index = proxy.index(row, 0)
self.treeview.expand(index)
or this:
proxy = self.treeview.model()
model = proxy.sourceModel()
for row in range(model.rowCount()):
index = model.index(row, 0)
self.treeview.expand(proxy.mapFromSource(index))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)