QML 發光呼吸動畫字型
阿新 • • 發佈:2019-01-24
前言
用 QML 來實現一個呼吸動畫效果的字型,非常酷炫,主要使用 Glow 元件來實現,然後通過控制透明度的改變來實現想要的效果,程式碼非常簡單。
正文
先來看看效果
原始碼:
Item {
Rectangle {
anchors.fill: parent
color: "black"
}
Text {
id: text
anchors.fill: parent
text: qsTr("ADBASn你好")
font.bold: true
font.pixelSize: 50
color:"white"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
Glow {
anchors.fill: text
radius:9
samples: 13
color: "#ddd"
source: text
spread: 0.5
opacity: 0.8
NumberAnimation on opacity {
id:an1
to:0.8
duration: 2000
running: true
onStopped: {
an2.start()
}
}
NumberAnimation on opacity {
id:an2
to:0.2
duration: 2000
onStopped: {
an1.start()
}
}
}
}
此外,還可以通過修改 Glow 的引數來實現不同的效果,具體可以看 Qt 幫助文件。
原始碼在這裡點選下載