【发布时间】:2015-04-01 07:52:57
【问题描述】:
如何将不同的模型分配给ListView,它位于Repeater 中?
我做了一个草图(我的实际项目要大得多):
Column {
Repeater {
model: ["Line1","Line2","Line3","Line4"]
Rectangle {
ListView {
model: ???
delegate: Rectangle {
Text {
text: somemodelproperty
}
}
}
}
}
}
目前,我正在通过复制粘贴 10 个矩形来解决这个问题,每个矩形都包含一个 ListView。在 C++ 中,我已经实现了 10 个QList<QObject*>,并且每个列表都“绑定”到一个ListView
QQmlContext * example = engine.rootContext();
example->setContextProperty(modelname,QVariant::fromValue(listobject));
我很确定有一种更智能的方法可以做到这一点,但我几天前才开始使用 QML,还没有找到解决方案。
【问题讨论】:
标签: c++ qt listview qml repeater