gpt4 book ai didi

qt - 中继器接入元件

转载 作者:行者123 更新时间:2023-12-02 09:32:27 24 4
gpt4 key购买 nike

我有以下中继器:

Repeater{
id: rainDropId
model: 200

delegate: Rectangle {

x: Math.floor(Math.random() * windowId.width)
y: Math.floor(Math.random() * windowId.height)
property int mLayer: Math.floor(Math.random() * 4) + 1

property double mYSpeed: -2.0 * mLayer

width:5
height:5
color: "#3399FF"
radius: width*0.5
}
}

我有一个计时器。我想根据自己的属性修改 Repeater 中所有元素的位置。如何从 Timer 访问类似 rainDropId[index] 的内容?

谢谢

最佳答案

使用RepeateritemAt()方法:

import QtQuick 2.4
import QtQuick.Window 2.2

Window {
id: windowId
visible: true
width: 400
height: 400

Repeater {
id: rainDropId
model: 200

delegate: Rectangle {
width:5
height:5
color: "#3399FF"
radius: width*0.5
}
}

Timer {
running: true
interval: 1000
repeat: true
triggeredOnStart: true
onTriggered: {
for (var i = 0; i < rainDropId.count; ++i) {
rainDropId.itemAt(i).x = Math.floor(Math.random() * windowId.width);
rainDropId.itemAt(i).y = Math.floor(Math.random() * windowId.height);
}
}
}
}

您也可以考虑使用Qt Quick Particles创建雨滴。

关于qt - 中继器接入元件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31455355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com