Qt 将动画应用于QML中栅格布局中的所有图像,而不是为每个图像设置动画
我有这段代码,问题是我需要在所有图像上应用动画,但找不到任何方法。感谢您的帮助Qt 将动画应用于QML中栅格布局中的所有图像,而不是为每个图像设置动画,qt,qml,qtquick2,Qt,Qml,Qtquick2,我有这段代码,问题是我需要在所有图像上应用动画,但找不到任何方法。感谢您的帮助 Image { id: img3 source: "iconborder.jpg" height:80 width:80 Image { id: img3icon source: "greenStone.jpg" height:70 width:70 z:1 anchors.c
Image {
id: img3
source: "iconborder.jpg"
height:80
width:80
Image {
id: img3icon
source: "greenStone.jpg"
height:70
width:70
z:1
anchors.centerIn:img3
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}
奇怪的是,您使用的是父/子图像,而不是兄弟姐妹图像,因为这对我来说更为自然,但无论哪种方式,这里都有来自的相关代码,如果您不希望将其更改为兄弟姐妹图像,则可以很容易地将其调整为您怪异的父/子图像代码:
...
// the sun, moon, and stars
Item {
width: parent.width; height: 2 * parent.height
NumberAnimation on rotation { from: 0; to: 360; duration: 10000; loops: Animation.Infinite }
Image {
source: "images/sun.png"; y: 10; anchors.horizontalCenter: parent.horizontalCenter
rotation: -3 * parent.rotation
}
Image {
source: "images/moon.png"; y: parent.height - 74; anchors.horizontalCenter: parent.horizontalCenter
rotation: -parent.rotation
}
...
如您所见,这些图像是兄弟图像,它们的动画基于父图像的动画。这样,两个图像将具有与您所希望的相同的动画效果。@Laszlo:图像一个用于图标边框,另一个用于实际图标。很抱歉,我只是一个初学者,对这里的情况有一点了解。很抱歉,@LaszloPapp,是的,它确实起作用了。!!