转换操作改变了一个对象的几何状态,QML元素对象能够被平移,旋转,缩放。
平移:通过改变x,y坐标实现的
旋转:改变rotation属性,这个值使用角度作为单位(0–360)
缩放:通过改变scale属性,小于1意味着缩放,大于1意味着放大
一:平移
每次点击,图片向右平移5个像素
ClickableImage {
id: rocket1
x: 20; y: 100
source: "assets/rocket.png"
onClicked: {
// increase the x-position on click
x += 5
}
}
二:旋转
每次点击,中心旋转5°
ClickableImage {
id: rocket2
x: 140; y: 100
source: "assets/rocket.png"
smooth: true // need antialising
onClicked: {
// increase the rotation on click
rotation += 5
}
}
三:缩放
ClickableImage {
id: rocket3
x: 240; y: 100
source: "assets/rocket.png"
smooth: true // need antialising
onClicked: {
// several transformat
scale -= 0.05
}
}