英文:
How to create a TreeView with Qt and Go?
问题
我正在尝试为我的应用程序创建一个Qt TreeView,我之前一直在使用ListView,但我认为TreeView更适合我的需求,然而文档几乎不存在。
要向ListView添加新项,可以使用以下代码:
var list = QNewListWidget(nil)
list.AddItem2("Sample")
然而,我一直在寻找如何将其更改为TreeView,以便我可以有以下结构:
Sample
- Sample child 1
- sample child 2
关于Go的文档几乎没有,有人知道我该如何做到这一点吗?
英文:
I'm trying to make a Qt TreeView for my application, I'd been using a ListView originally but I think a treeview would suit my needs better however the documentation is almost none existent.
to add a new item to a listview is use
var list = QNewListWidget(nil)
list.AddItem2("Sample")
however I've been looking to change it to a treeview so I can have:
Sample
- Sample child 1
- sample child 2
The documentation almost seems no existent for Go, anyone know how I can do this ?
答案1
得分: 1
对于任何想知道的人,我终于解决了。你需要添加一个不可见的项目,并将你的父项目作为子项目添加到其中:
list_item := widgets.NewQTreeWidgetItem2([]string{"示例项目"}, 0)
root := pointsOfInterest.InvisibleRootItem()
root.AddChild(list_item)
child_list_item := widgets.NewQTreeWidgetItem2([]string{"子项目"}, 0)
list_item.AddChild(child_list_item)
英文:
For anyone wondering, I finally worked it out. You have to add an invisible item and add your parent items as a child to that:
list_item := widgets.NewQTreeWidgetItem2([]string{"Sample Item"}, 0)
root := pointsOfInterest.InvisibleRootItem()
root.AddChild(list_item)
child_list_item := widgets.NewQTreeWidgetItem2([]string{"Child item"}, 0)
list_item.AddChild(child_list_item)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论