PyQt怎么删除treeview所有节点

809
2023/11/19 9:15:50
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

要删除Qt中的所有节点,可以使用以下方法:
1.获取treeview的根节点:

root = treeview.invisibleRootItem()

2.获取根节点的子节点数量:

child_count = root.childCount()

3.循环删除子节点:

for i in range(child_count):

????child?=?root.child(i)

????root.removeChild(child)

完整代码如下:

root?=?treeview.invisibleRootItem()
child_count?=?root.childCount()
for?i?in?range(child_count):

????child?=?root.child(i)

????root.removeChild(child)

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: winform treeview递归加载数据库怎么实现