微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在QML SwipeView中闪烁

如何解决在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模型最初为空时,
  1. 更新问题不会出现
  2. 使用没有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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?