QML:如何在TreeView中的委托中获取QModelIndex

时间:2018-05-04 07:59:45

标签: qt qml qt5 qmodelindex

我在qml TreeView中有一个委托。我想得到它QModelIndex。大街

 model.index

我只获得代表所在行的编号。但是,我需要将QModelIndex传递给c ++端(制作QPersistentModelIndex并存储以供以后使用)。

1 个答案:

答案 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