我在qml TreeView
中有一个委托。我想得到它QModelIndex
。大街
model.index
我只获得代表所在行的编号。但是,我需要将QModelIndex
传递给c ++端(制作QPersistentModelIndex
并存储以供以后使用)。
答案 0 :(得分:2)
根据docs:
itemDelegate:Component
此属性定义用于绘制特定单元格的委托。
在项目委托中,您可以访问以下特殊内容 属性:
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
。