Qt qml中使用listView加载组件问题

    xiaoxiao2021-03-25  89

      最近遇到了一个关于ListView的问题,ListView的每个列表上几个比较简单的控件,刚开始由于数据是实时更新的所以当数据较多时在对ListView进行添加行或者删除行操作后需要重新加载数据,当操作过于频繁时就会出现“假死机”。

    于是我使用了

    ListView.onAdd: SequentialAnimation {                 PropertyAction { target: listItem; property: "height"; value: 0 }                 NumberAnimation { target: listItem; property: "height"; to: listItem.height; duration: 250; easing.type: Easing.InOutQuad }             }             ListView.onRemove: SequentialAnimation {                 PropertyAction { target: listItem; property: "ListView.delayRemove"; value: true }                 NumberAnimation { target: listItem; property: "height"; to: 0; duration: 250; easing.type: Easing.InOutQuad }                 // Make sure delayRemove is set back to false so that the item can be destroyed                 PropertyAction { target: listItem; property: "ListView.delayRemove"; value: false }             }

      实现原理:使用ListView.onAdd、ListView.onRemove操作界面的增删,实际数据的增删由cpp完成,只需保证界面和后台相同的操作,这样就不需要重新加载数据,问题就迎刃而解。

      可能还有更好的方法,这只是我自己的拙见,望指教。

    转载请注明原文地址: https://ju.6miu.com/read-14359.html

    最新回复(0)