效果:
?
1,创建QT QUICK APPLICATION ,添加元素RECT,TEXT,界面如下:
?qml 代码
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
color: "#ffffff"
title: qsTr("Hello World")
Rectangle {
id: rectangle
x: -8
y: 0
width: 648
height: 480
color: "#519809"
}
Text {
id: element
x: 232
y: 206
color: "#ffffff"
text: qsTr("你好 CSDN")
font.pixelSize: 32
}
}
2,在Rectangel中添加颜色动画。
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
color: "#ffffff"
title: qsTr("Hello World")
Rectangle {
id: rectangle
x: -8
y: 0
width: 648import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
color: "#ffffff"
title: qsTr("Hello World")
Rectangle {
id: rectangle
x: -8
y: 0
width: 648
height: 480
color: "#519809"
//动画代码
SequentialAnimation on color
{
ColorAnimation {
// from: "white"
to: "yellow"
duration: 1000
}
ColorAnimation {
// from: "white"
to: "red"
duration: 1000
}
ColorAnimation {
//from: "white"
to: "blue"
duration: 1000
}
loops:Animation.Infinite;
}
//----------------
}
Text {
id: element
x: 232
y: 206
color: "#ffffff"
text: qsTr("你好 CSDN")
font.pixelSize: 32
}
}
height: 480
color: "#519809"
//-------------以下为颜色动画代码
SequentialAnimation on color
{
ColorAnimation{to:"yellow";duration:1000}
ColorAnimation{to:"red"; duration:1000}
ColorAnimation{to:"blue";duration100 }
loops:Animation.Infinite;
}
//---------------
}
Text {
id: element
x: 232
y: 206
color: "#ffffff"
text: qsTr("你好 CSDN")
font.pixelSize: 32
}
}
3,举一反三,添加按钮的透明,旋转动画。
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
color: "#ffffff"
title: qsTr("Hello World")
Rectangle {
id: rectangle
x: -8
y: 0
width: 648
height: 480
color: "#519809"
SequentialAnimation on color
{
ColorAnimation {
// from: "white"
to: "yellow"
duration: 1000
}
ColorAnimation {
// from: "white"
to: "red"
duration: 1000
}
ColorAnimation {
//from: "white"
to: "blue"
duration: 1000
}
loops:Animation.Infinite;
}
}
Text {
id: element
x: 232
y: 206
color: "#ffffff"
text: qsTr("你好 CSDN")
font.family: "Arial"
font.pixelSize: 32
SequentialAnimation on opacity
{
NumberAnimation{to:0;duration:500}
NumberAnimation{to:1;duration:500}
loops:Animation.Infinite;
}
NumberAnimation on rotation
{
from:0;
to:360;
duration: 2000;
loops:Animation.Infinite;
}
}
}
|