当前位置: 代码网 > it编程>App开发>Android > Qml学习——动画

Qml学习——动画

2024年08月01日 Android 我要评论
Qml学习——动画

最近在学习qml,但对qml的各种用法都不太熟悉,总是会搞忘,所以写几篇文章对学习过程中的遇到的东西做一个记录。
学习参考视频:https://www.bilibili.com/video/bv1ay4y1w7xd?p=1&vd_source=0b527ff208c63f0b1150450fd7023fd8
其他文章:
qml学习——动态加载控件
qml学习——控件状态
qml学习——使用javascript
qml学习——动画
qml学习——鼠标事件处理mousearea
qml学习——布局
qml学习——基本控件


1 behavior

import qtquick 2.12
import qtquick.window 2.12
import qtquick.controls 2.12

window {
    visible: true; width: 200; height: 120

    rectangle {
        width: 50; height: 40
        color: 'red'

        behavior on width {
            numberanimation {
                duration: 500
            }
        }

        mousearea {
            anchors.fill: parent
            onclicked: {
                if (parent.width == 50) {
                    parent.width = 100
                } else {
                    parent.width = 50
                }
            }
        }
    }
}

请添加图片描述

2 animation

2.1 动画组

import qtquick 2.12
import qtquick.window 2.12
import qtquick.controls 2.12

window {
    visible: true; width: 200; height: 120

    rectangle {
        id: rect
        width: 50; height: 40
        color: 'red'

        sequentialanimation {
            loops: animation.infinite
            running: true
            numberanimation {
                property: 'width'
                target: rect
                to: 100
                duration: 500
            }

            numberanimation {
                property: 'width'
                target: rect
                to: 70
                duration: 300
            }

            numberanimation {
                property: 'width'
                target: rect
                to: 150
                duration: 500
            }

            numberanimation {
                property: 'width'
                target: rect
                to: 50
                duration: 500
            }
        }
    }
}

请添加图片描述

2.1 并行动画

import qtquick 2.12
import qtquick.window 2.12
import qtquick.controls 2.12

window {
    visible: true; width: 200; height: 120

    rectangle {
        id: rect
        width: 50; height: 50
        color: 'red'

        sequentialanimation {
            loops: animation.infinite
            running: true

            parallelanimation {
                running: true
                numberanimation {
                    property: 'width'
                    target: rect
                    to: 100
                    duration: 500
                }

                numberanimation {
                    property: 'height'
                    target: rect
                    to: 100
                    duration: 500
                }
            }

            parallelanimation {
                running: true
                numberanimation {
                    property: 'width'
                    target: rect
                    to: 50
                    duration: 500
                }

                numberanimation {
                    property: 'height'
                    target: rect
                    to: 50
                    duration: 500
                }
            }
        }
    }
}

请添加图片描述

3 state切换的过渡动画(transition)

import qtquick 2.12
import qtquick.window 2.12
import qtquick.controls 2.12

window {
    visible: true; width: 200; height: 120

    rectangle {
        id: rect
        width: 50; height: 40
        color: 'red'

        transitions: [
            transition {
                numberanimation {
                    property: 'width'
                    duration: 500
                }
            }
        ]


        states: state {
            name: 'demo'
            propertychanges {
                target: rect
                width: 100

            }
        }

        mousearea {
            anchors.fill: parent
            onclicked: {
                rect.state = rect.state ? '' : 'demo'
            }
        }
    }
}

请添加图片描述

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com