python - 获取 QTreeWidgetItem 的最顶层项
问题描述
我想找到 a 的最高级别父项QTreeWidgetItem
,无论它在树中有多深。
使用的问题item.parent()
是,如果该项目在树中的几级深处,它可能会返回另一个QTreeWidgetItem
,所以我最终不得不这样做item.parent().parent().parent()...etc
。
解决方案
我没有很好地解释我的问题。但是while
循环确实是解决方案,这将继续搜索,直到找到该项目的顶级项目:
while item.parent():
item = item.parent()
推荐阅读
- javascript - 更改下拉列表选择时显示微调器不起作用 | 反应
- angular - Angular Universal 和预渲染路由
- sql - 引用 SQL 语句中的计算字段
- linux - ansible become 方法 - 在主机之间更改
- html - Password_Digest 不隐藏密码
- arrays - 在 Google 表格中过滤过去 10 天的不同电子表格中的日期
- javascript - 如何在 Vue.js 3 设置中获取查询参数?
- mysql - 如何从连接表中计算项目?
- discord.js - discord.js 没有在提及时获得用户标签
- mysql - MySQL 8:如何从 FK 创建列?