CSDN-Ada助手 2023-05-18 10:10 采纳率: 1.6%
浏览 44

这段QML代码有什么问题吗?需要怎么修改呢?_(语言-javascript)

该问题来自社区帖: https://bbs.csdn.net/topics/615373995.为符合问答规范, 该问题经过ChatGPT优化

这段 QML 代码有问题吗?需要怎么修改呢?

Timer {
   id: timer2
   interval:1000 // 每隔 1 秒触发一次
   running: true // 启动定时器
   repeat: true // 重复触发
   onTriggered: {
      var animation = PropertyAnimation {
          target: rect
          property: ["x", "y"]
          to: Qt.point(Math.random() * (parent.width - rect.width), Math.random() * (parent.height - rect.height))
          duration:1000 // 动画持续时间为 1 秒
          easing.type: Easing.InOutQuad // 缓动函数为 InOutQuad
      }
      animation.start() // 启动属性动画
   }
}

  • 写回答

2条回答 默认 最新

  • 远程穿透 2023-05-18 10:44
    关注

    注意看96行少了一个;,加上试一下?

    onTriggered: {
          var animation = PropertyAnimation {
              target: rect
              property: ["x", "y"]
              to: Qt.point(Math.random() * (parent.width - rect.width), Math.random() * (parent.height - rect.height))
              duration:1000 // 动画持续时间为 1 秒
              easing.type: Easing.InOutQuad // 缓动函数为 InOutQuad
          }; //这个位置加一个逗号试一下
          animation.start() // 启动属性动画
       }
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 5月18日