如何解决在QML SwipeView中闪烁
重置中继器的模型时,QML swipeview出现更新问题。 Qt版本是5.12。
说明
在(https://doc.qt.io/qt-5/qml-qtquick-controls2-swipeview.html)中的文档之后,实现了swipeview。与链接中所述示例的不同之处在于,未使用任何加载程序。中继器的模型是由父视图以QAbstractListModel的形式注入的。
重置viewmodel时,swipeview出现更新问题。这会导致第一页的几次重绘。对于用户来说,这似乎是视图在闪烁。下面介绍QAbstractListModel的QML文件和更新功能。
QML文件:
Item {
id: root
/**
Set the model (is of type QAbstractListModel
**/
property var viewmodel
height: 30 * Screen.pixelDensity
width: 60 * Screen.pixelDensity
Rectangle {
id: wrapper
anchors.fill: parent
color: "grey"
swipeview {
id: swipe
clip: true
anchors.fill: parent
Repeater {
model: root.viewmodel
Rectangle {
width: 20
height: 20
border.color: "black"
border.width: 1
Text {
text: index
}
}
}
}
}
}
更新功能:
void DerivedQAbstractList::setPages(const std::vector<Pages> &pages)
{
beginResetModel();
// create internal data structure
endResetModel();
}
观察:
-
当QAbstractList模型最初为空时,
- 更新问题不会出现。
- 使用没有swipeview的中继器可以正常工作(例如,列{Repeater {...}}
您是否有任何想法可能是问题所在。还是给我另一种方法来使用动态模型进行滑动查看?
编辑1.0。使用实例化器 如评论中的要求,我们尝试用Instantiator替换Repeater。我们可以从控制台日志中看到已创建组件。但是,它们不会出现在屏幕上。我们想念什么?
Rectangle {
id: wrapper
anchors.fill: parent
color: "grey"
swipeview {
id: swipe
clip: true
anchors.fill: parent
Instantiator {
model: root.viewmodel
delegate: Rectangle {
Component.onCompleted: console.log("Created")
width: 20
height: 20
border.color: "black"
border.width: 1
Text {
text: index
}
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。