在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.JdbcOdbc...