我创建了一个应该如下所示的树视图:
parent1
path branch [button]
path branch [button]
...
我像这样创建树
def create_tree(self,containerWidget):
self.repo_tree = QTreeView(self)
self.repo_tree.setGeometry(10, 10, 580, 380)
self.repo_tree_model = QStandardItemModel()
self.repo_tree.setModel(self.repo_tree_model)
containerWidget.addWidget(self.repo_tree)
我像这样添加父母和孩子
def add_tree_repo(self,repo_url, repo_name, branch, repo_path,config,worktrees):
root_item = QStandardItem(repo_name)
self.repo_tree_model.appendRow(root_item)
for worktree in worktrees:
child1 = QStandardItem(worktree["path"])
child2 = QStandardItem("[" + worktree["branch"] + "]")
root_item.appendRow([child1,child2])
button = QToolButton()
button.setMaximumSize(button.sizeHint())
self.repo_tree.setIndexWidget(child2.index(), button)
self.repo_tree.update()
self.repo_tree.expandAll()
仅显示路径:
parent1
path
path
...
我错过了什么?任何帮助表示赞赏
显然这解决了问题
self.repo_tree_model.setHorizontalHeaderLabels(["Column 1", "Column 2", "Column 3"])