标签:
杂谈 |
1、
代码如下:
- Rectangle
{ - opacity:0.5//透明度为0.5
- color:"red"
- y:400;width:100;height:100
- Rectangle {
- x:50;y:50
- width:100;height:100
- color:"blue"
- }
- }
代码如下:
- Rectangle
{ - opacity:0.5
- color:"red"
- y:400;width:100;height:100
- Rectangle {
- x:50;y:50
- width:100;height:100
- color:"blue"
- rotation:30//顺时针旋转30度。
- smooth:true
- }
- }
3、
代码如下:
- Rectangle {
- color:"lightgray"
- width:100;height:100
- y:400;x:290
- Rectangle {
- color:"green"
- width:25;height:25
- }
- Rectangle {
- color:"yellow"
- x:25;y:25;width:50;height:50
- scale:1.5//放大1.5倍。
- transformOrigin:Item.TopLeft
- }
- }
4、
就是我们缩放和旋转时时基于那个点或者线来实现的?
这个可以使用transformOrigin属性来设置,该属性的取值为:TopLeft、Top、TopRight、Left、Center、Right、BottomLeft、Bottom、BottomRight。
5、
代码如下:
// 竖直渐变
- Rectangle {
- x:120;width:100;height:100
- gradient:Gradient {
- GradientStop {position:0.0;color:"lightgreen"}
- GradientStop {position:1.0;color:"lightgray"}
- }
- }
- // 水平渐变
- Rectangle {
- x:120;width:100;height:100
- gradient:Gradient {
- GradientStop {position:0.0;color:"lightgreen"}
- GradientStop {position:1.0;color:"lightgray"}
- }
- rotation:90
- }
- }
6、Animation and Transitions
1)SequentialAnimation
代码如下:
- Rectangle {
-
id: rect -
width: 100; height: 100 -
color: "red" -
SequentialAnimation { -
running: true -
NumberAnimation { target: rect; property: "x"; to: 50; duration: 1000 } -
NumberAnimation { target: rect; property: "y"; to: 50; duration: 1000 } -
} - }
2) ParallelAnimation 并联运行动画
代码如下:
- Rectangle {
-
id: rect -
width: 100; height: 100 -
color: "red" -
ParallelAnimation { -
running: true -
NumberAnimation { target: rect; property: "x"; to: 50; duration: 1000 } -
NumberAnimation { target: rect; property: "y"; to: 50; duration: 1000 } -
} - }
3) NumberAnimation 数值动画
代码如下:
- Rectangle {
-
width: 100; height: 100 -
color: "red" -
NumberAnimation on x { to: 50; duration: 1000 } - }
4) ColorAnimation 颜色动画
代码如下:
- Rectangle {
-
width: 100; height: 100 -
color: "red" -
ColorAnimation on color { to: "yellow"; duration: 1000 } - }
5) RotationAnimation 旋转动画
代码如下:
- Item {
-
width: 300; height: 300 -
Rectangle { -
id: rect -
width: 150; height: 100; anchors.centerIn: parent -
color: "red" -
smooth: true -
states: State { -
name: "rotated" -
PropertyChanges { target: rect; rotation: 180 } -
} -
transitions: Transition { -
RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise } -
} -
} -
MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" } - }
还有如Behavior、ParallelAnimation、PropertyAnimation、Vector3dAnimation、ParentAnimation、AnchorAnimationt等,这里就不多做介绍,可以查看QT SDK的帮助文档。
前一篇:qml 1
后一篇:编写QML工程应该注意的事项