【发布时间】:2021-02-07 22:31:13
【问题描述】:
我有一个 listview 突出显示组件,我需要在该组件之外使用它的 id(列表视图内部和外部),但无论我尝试什么,我都会得到一个 reference error: Id is not defined. 无法找到解决方法。我在某处读到,由于突出显示的类型是组件,因此不能在它之外使用。但是我真的需要在外面使用这个id。有人可以帮忙吗
我目前拥有的代码的一个小轮廓是
ListView {
id: listId
MouseArea {
anchors.fill: parent
onClicked: {
boxId.visible = false
} //unable to use 'boxId' like this. Getting reference error
}
delegate: Rectangle {}
highlight: Rectangle {
id: boxId
}
}
【问题讨论】:
-
由于范围限制,您无法访问
Listview.highlight组件。它在访问时根本不存在。你不应该那样做,想想declarative。如果您仍想遵循命令式风格,请使用Listview.highlightItem 引用突出显示的项目。
标签: qt listview qml highlight referenceerror