我有一个c++类,我在qml中注册了它,这个类有一个从QAbstractListModel继承的模型,现在我希望这个模型具有一个SwipeView
Manager {
id: manager
}
SwipeView {
id: sv
model:manager.listModel /// but it don't have model property
}但是SwipView没有模型属性吗?应该如何将页面动态地添加到这个模型中呢?
发布于 2019-05-24 20:39:28
您可以使用Repeater作为医生们的示例
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
ListModel{
id: mymodel
ListElement{
name: "name1"
background: "red"
}
ListElement{
name: "name2"
background: "salmon"
}
ListElement{
name: "name2"
background: "gray"
}
}
SwipeView{
id: view
anchors.fill: parent
Repeater{
model: mymodel
Rectangle{
color: model.background
Text {
anchors.centerIn: parent
text: model.name
}
}
}
}
}https://stackoverflow.com/questions/56298787
复制相似问题