qml 竖着滚动字

大致思路: 就是放两个文字,一个在显示区域,一个在显示区域的下面,大小都和显示区域相同。让后通过qml的动画更改两个Text的y属性。
自己做的时候,一直出现两个文字都是显示不管在不在显示区域。后来发现有个属性:clip   设置为true后就可以。clip裁剪,到现在。总算是明白它的意思了。
动画要用以个串行动画里面包含一个并行的动画和一个直接的y变化的动画。不过,直接用一个并行的动画执行貌似也没有什么问题。

Item {
    id: root
    width: 100
    height: 80
    clip: true
    Column{
        Text{
            id: text1
            text: "1111111111"
            width: root.width
            height: root.height
            font.pixelSize: 40
        }
        Text{
            id: text2
            text: "2222222222"
            width: root.width
            height: root.height
            font.pixelSize: 40
        }
    }
    SequentialAnimation {
        id: animation
        running: false
        ParallelAnimation{
            NumberAnimation{
                target: getObj(1)
                property: "y"
                from: 0
                to: -root.height
                duration: 3000
            }
            NumberAnimation{
                target: getObj(0)
                property: "y"
                from: root.height
                to: 0
                duration: 3000
            }
        }
        NumberAnimation{
            target: getObj(1)
            property: "y"
            to: root.height
            duration: 0
        }
    }
    property int type: 1
    function scrooll() {
        animation.running = true;
        if(type === 1) {
            type = 0;
        } else {
            type = 1;
        }
    }
    function getObj(data) {
        if(data === type) {
            return text1;
        } else {
            return text2;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值