【问题标题】:How Use ListModel with SwipeView?如何使用 ListModel 和 SwipeView?
【发布时间】:2019-10-11 10:03:42
【问题描述】:
我有一个在 qml 中注册的 c++ 类,并且这个类有一个继承自 QAbstractListModel 的模型,现在我想要这个带有 SwipeView 的模型
Manager {
id: manager
}
SwipeView {
id: sv
model:manager.listModel /// but it don't have model property
}
但是 SwipView 没有模型属性? id 应该如何将 Pages 与此模型一起动态添加到 thsi swipeview?
【问题讨论】:
标签:
qt
qml
qt-quick
qtquickcontrols
swipeview
【解决方案1】:
您可以使用中继器作为the docs 的示例:
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
}
}
}
}
}