qml调用html慢,如何在QML中延迟JavaScript操作?

它已经有一段时间了,我错过了QML。但让我试着提出一个解决方案。我想这可能会起作用,如果你在Component.onComlpeted事件中调用translationAnimation.running = true。我之前发布了一个愚蠢的答案。现在我用一种懒惰/丑陋的方式取代它来做到这一点。这可能不是正确的做法,尽管此代码可能有助于您的用例。

CreateObject.js

.pragma library

var objects = null;

var objectCount = 0;

var i = 0;

var mainWin;

var x = 0;

var y = 0;

function calledOnbuttonAction(parentWindow)

{

if(objects === null)

{

mainWin = parentWindow;

x = 0;

y = 0;

objects = new Array();

createObject(x,y);

}

else

{

if(x <= mainWin.width)

x = x + 28;

else

{

x = 0;

if(y <= mainWin.height)

y = y + 28;

else

{

console.debug("Exceeded window area!")

return;

}

}

createObject(x,y);

}

}

function createObject(xPos, yPos)

{

i++;

var component = Qt.createComponent("Object.qml");

objects[objectCount++] = component.createObject(mainWin, {"x": xPos, "y": yPos});

}

main.qml

import QtQuick 1.1

import "CreateObjects.js" as CreateObject

Rectangle {

id: mainWindow

width: 360

height: 360

Text {

text: qsTr("Click inside window")

anchors.centerIn: parent

font.pixelSize: 18

}

MouseArea {

anchors.fill: parent

onClicked: {

CreateObject.calledOnbuttonAction(mainWindow); //passing the parent window object

}

}

}

Object.qml //符号在你的情况

//The Symbol

import QtQuick 1.1

import "CreateObjects.js" as CreateObject

Rectangle {

id: obj

width: 25

height: 25

gradient: Gradient {

GradientStop {

position: 0

color: "#d11b1b"

}

GradientStop {

position: 1

color: "#ea4848"

}

}

property alias animationStatus: completedAnimation

NumberAnimation {

id: completedAnimation;

target: obj;

property: "opacity";

duration: 800;

from: 0;

to: 1.0;

onRunningChanged: {

if(!running && CreateObject.i < 900) // Decrease or increase the value according to the number of objects you want to create

{

CreateObject.calledOnbuttonAction();

}

}

}

Component.onCompleted: completedAnimation.running = true;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值