加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

QML延时执行语句代码

(2018-11-16 12:32:13)
标签:

qml

分类: QT

import QtQuick 2.0

 

Rectangle {

    width: 800

    height: 600

 

    color: "brown"

   

    Repeater{

        id:myrepeater

        model:2

        Item {

          

            Timer {

                id: timer

               

            }

           

            function delay(delayTime, cb) {

                timer.interval = delayTime;

                timer.repeat = false;

                timer.triggered.connect(cb);

                timer.start();

                }

               

            Text { id: mytext; text:"test"}

           

        }

    }

 

 

 

    Rectangle {

       

        id: rectangle

        color: "yellow"

        anchors.fill: parent

        anchors.margins: 100

        opacity: 0

 

        Behavior on opacity {

            NumberAnimation {

                duration: 5000

            }

        }

    }

   

    Rectangle {

        id: rectangle2

        color: "Green"

        anchors.fill: parent

        anchors.margins: 200

        opacity: 0

 

        Behavior on opacity {

            NumberAnimation {

                duration: 0

            }

        }

    }

 

    Component.onCompleted: {

        print("I'm printed right away..")

        myrepeater.itemAt(0).delay(2000, function() {

            print("And I'm printed after 2 second!")

            rectangle.opacity = 1

        })

        myrepeater.itemAt(1).delay(5000, function() {

            print("And I'm printed after 5 second!")

            rectangle2.opacity = 1

        })

    }

}

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有