[英]Qt qml - how to use component in its definition?
I have to implement TreeView
in qml
. 我必须在
qml
实现TreeView
。 Basically because each subtree is just TreeView
itself, i want to use TreeView
component in TreeView
definition (this is that Repeater
on the end). 基本上因为每个子树都只是
TreeView
本身,所以我想在TreeView
定义中使用TreeView
组件(这是最后的Repeater
)。
This is part of code where i reference the component i am defining. 这是代码的一部分,其中引用了我正在定义的组件。
You can see that rootDelegate
is actually id
of the Component
. 您可以看到
rootDelegate
实际上是Component
id
。
Problem is Qt gives error Unable to assign QQuickRow to QQmlComponent 问题是Qt提供错误无法将QQuickRow分配给QQmlComponent
Repeater {
model: childrens
delegate: rootDelegate
}
TreeView.qml TreeView.qml
import QtQuick 2.0
Component {
id: rootDelegate
Column {
Row {
id: itemControl
spacing: 2
Rectangle {
anchors.verticalCenter: parent.verticalCenter
gradient: Gradient {
GradientStop { position: 0.0; color: "#EEEEEE" }
GradientStop { position: 1.0; color: "#404040" }
}
width: openChar.implicitWidth
height: openChar.implicitHeight - 6
radius: 3
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
}
Text {
id: openChar
text: "+"
color: "black"
anchors.centerIn: parent
}
}
Rectangle {
height: 1
color: "#A0A0A0"
width: 10
anchors.verticalCenter: parent.verticalCenter
}
Text {
text: model.text
color: "white"
}
}
Repeater {
model: childrens
delegate: rootDelegate
}
}
}
您正在尝试递归使用Сomponent,但Qml不允许使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.