qt - QML:如何在 TreeView 内的委托中获取 QModelIndex
问题描述
我在 qml 中有一个代表TreeView
。我想得到它的QModelIndex
. 通过
model.index
我只得到代表所在的行号。但是,我需要将 a 传递QModelIndex
给 c++ 端(制作 aQPersistentModelIndex
并将其存储以备后用)。
解决方案
根据文档:
itemDelegate : 组件
这个属性定义了一个委托来绘制一个特定的单元格。
在项目委托中,您可以访问以下特殊属性:
styleData.selected - if the item is currently selected styleData.value - the value or text for this item styleData.textColor - the default text color for an item styleData.row - the index of the view row styleData.column - the index of the view column styleData.elideMode - the elide mode of the column styleData.textAlignment - the horizontal text alignment of the column styleData.pressed - true when the item is pressed styleData.hasActiveFocus - true when the row has focus styleData.index - the QModelIndex of the current item in the model styleData.depth - the depth of the current item in the model styleData.isExpanded - true when the item is expanded styleData.hasChildren - true if the model index of the current item has or can have children styleData.hasSibling - true if the model index of the current item has a sibling
在您的情况下,您必须使用styleData.index
.
推荐阅读
- java - 露天听众
- type-conversion - Pentaho HBase 导入:从 HBase 中提取日期数据类型抛出错误
- javascript - 使用 Browserify 编译 NPM 包
- neo4j - 如何匹配具有超过 1 个指定关系的节点
- r - 如何在 R 中使用 library(maps) 和 ggplot 绘制东非(肯尼亚、乌干达和坦桑尼亚)地图?
- ssis - dat 文件导入到 sql server
- java - 如何在 Android 的 Cloud Firestore 中修补 JSON?
- java - 如何在 Windows 10 中计算 Java 代码的能耗(焦耳)
- python - 使用包的 Python 项目中的 ModuleNotFoundError
- java - 更改位置引擎请求间隔