为 TableView 中的新项目设置动画 [英] Animate new items in a TableView

查看:48
本文介绍了为 TableView 中的新项目设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 TableView 来显示 SQLite 数据库的内容.用户单击其中一个可检查按钮,然后通过 LocalStorage API 读取正确的表格.因此,模型总是新的.

I'm using a TableView to display the contents of an SQLite database. The user clicks one of the checkable buttons and the right table is read through the LocalStorage API. Thus, the model is always new.

因为模型总是新的,新表的加载在视觉上并不吸引人(所有条目都显示一次).

Because the model is always new, the loading of the new table isn't visually attractive (all the entries are shown at once).

我的想法是在添加行时为行的高度设置动画(以从 0 开始的线性方式)

My idea was to animate the height of the row when it's added (in a linear way from 0)

这是否可以在不从头开始重新实现 rowDelegate 的情况下完成?

Can this be done without reimplementing the rowDelegate from scratch?

推荐答案

是的,这是可能的.

TableView 使用 ListView 作为内部对象.您可以使用属性 __listView 访问它.

TableView uses ListView as internal object. You can access to it, using property __listView.

使用 ListView,可以指定在视图中的项因修改视图模型而发生更改时应应用的转换.

With ListView, it is possible to specify transitions that should be applied whenever the items in the view change as a result of modifications to the view's model.

Transition {
    id: populateTransition
    NumberAnimation { properties: "y"; duration: 300 }
}

TableView {
    TableViewColumn {
        role: "title"
        title: "Title"
        width: 100
    }
    model: libraryModel
    Component.onCompleted: {
        this.__listView.populate = populateTransition
        this.__listView.add = populateTransition
    }
}

附言此解决方案依赖于修改内部对象,并不能保证跨不同的 Qt 版本或平台工作.

P.S. this solution relies on modifying an internal object and is not guaranteed to work across different Qt versions or platforms.

这篇关于为 TableView 中的新项目设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆