Qml:Delegate/Model 浮动模型项目的组件
Qml: Delegate/Model component for floating model items
我有一组动态的 QML 组件(这些组件基于 on/combine 不同的控件,例如图像、标签...),它们显示在父控件中的 "arbitrary" 个位置上。每个组件的位置由底层对象 (C++) 定义。目前我使用 dynamic object creation 创建和删除这些组件,每次创建或删除新的底层对象时。
虽然这可行,但使用具有底层 QAbstractItemModel 的 delegate/model 方案会更干净。是否有内置组件,例如允许自由定位 QAbstractItemModel 的项目的组件?
[编辑]:这是对我的意思的描述:
此致,
您可以使用 Repeater
,它通常与行或列一起使用来布置内容,但它也适用于独立项目。
除此之外,您还有添加和删除项目的信号。
Repeater {
model: 20
delegate: Rectangle {
width: 50
height: 50
color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
MouseArea {
anchors.fill: parent
onPositionChanged: {
parent.x += mouseX
parent.y += mouseY
}
}
}
}
我有一组动态的 QML 组件(这些组件基于 on/combine 不同的控件,例如图像、标签...),它们显示在父控件中的 "arbitrary" 个位置上。每个组件的位置由底层对象 (C++) 定义。目前我使用 dynamic object creation 创建和删除这些组件,每次创建或删除新的底层对象时。
虽然这可行,但使用具有底层 QAbstractItemModel 的 delegate/model 方案会更干净。是否有内置组件,例如允许自由定位 QAbstractItemModel 的项目的组件?
[编辑]:这是对我的意思的描述:
此致,
您可以使用 Repeater
,它通常与行或列一起使用来布置内容,但它也适用于独立项目。
除此之外,您还有添加和删除项目的信号。
Repeater {
model: 20
delegate: Rectangle {
width: 50
height: 50
color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
MouseArea {
anchors.fill: parent
onPositionChanged: {
parent.x += mouseX
parent.y += mouseY
}
}
}
}