如何在与itemdelegate属性关联的组件外部访问StyleData.value?

时间:2017-04-10 23:34:29

标签: c++ qt treeview qml

我有一个QML TreeView,它包含一个分配给itemdelegate属性的CustomQml,进入CustomQml我可以访问所有style.data属性以及在C ++类中定义并由Q_PROPERTY公开的属性,但我想访问这些组件外的属性。

TreeView 
{
   id: tree
   anchors.fill: parent
   model: theModel
   property var selectedRowIndex;
   itemDelegate:  CustomNode{ id: node }

   selection: sel

   TableViewColumn {
       role: "title"
       title: "Scenegraph"
   }

   style: TreeViewStyle {
       branchDelegate: Rectangle {
           width: 16; height: 16
           color: styleData.isExpanded ? "green" : "red"
       }

       rowDelegate: Rectangle {
             width: 18; height: 18
       }

       highlightedTextColor: "black"
       alternateBackgroundColor: "grey"
    }

   MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.RightButton
        hoverEnabled: true
        onEntered: tree.selection.setCurrentIndex(theModel.index,sel.ClearAndSelect)

        onClicked: {
           var index = parent.indexAt(mouse.x, mouse.y)
           if (index.valid) {
               menu.popup()
               tree.selection.setCurrentIndex(index,sel.ClearAndSelect)
               // I want to access styleData.value.myproperty here, but this property is always "undefined"
               myFuction(styleData.value.myproperty) 
           }
        }
   }
}

访问这些属性的正确方法是什么以及我应该采取哪些措施来解决这个问题?

提前致谢!

0 个答案:

没有答案