【问题标题】:QML: How to get the QModelIndex in a delegate inside a TreeViewQML:如何在 TreeView 内的委托中获取 QModelIndex
【发布时间】:2018-09-23 12:59:13
【问题描述】:

我在 qml TreeView 中有一个代表。我想得到它的QModelIndex。通过

 model.index

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

【问题讨论】:

    标签: qt qml qt5 qmodelindex


    【解决方案1】:

    根据docs

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-25
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      相关资源
      最近更新 更多