此文通過QML實作了跑馬燈效果,為拋磚引玉,在此基礎上可以實作更多控制。
一、效果:
1、漸變背景;
2、文字置頂,從左至右,回圈跑馬。
二、直接上代碼,干脆利落:
QML:
//RunHorseText.qml
import QtQuick 2.0
import QtGraphicalEffects 1.0
import QtQuick.Controls 1.2
Item {
id: rootWidget
width: 1080
height: 100
Text {
id: linearLabel
font.bold: true
font.pixelSize: 50
color: "red"
font.family: "微軟雅黑"
text: "You are welcome!"
z:1
}
LinearGradient {
anchors.fill: parent
start: Qt.point(0, parent.height/2)
end: Qt.point(parent.width, parent.height/2)
gradient: Gradient {
//position可以更改線性透明的位置, color 就是字體的顏色(兩邊應該是透明的)
//這里是字體后面背景
GradientStop { position: 0.0; color: Qt.rgba(255,255,255,0.1) }
GradientStop { position: 0.3; color: "blue" }
GradientStop { position: 0.7; color: "blue" }
GradientStop { position: 1.0; color: Qt.rgba(255,255,255,0.1) }
}
}
PathAnimation{
id: pathTextMove
target: linearLabel
//影片的持續時間
duration: 6000
//影片持續的次數
loops: 2000
orientationEntryDuration: 0;
orientationExitDuration: 0;
orientation: PathAnimation.LeftFirst
path:Path{
startX: rootWidget.width + linearLabel.width/2
startY: rootWidget.height/2 - linearLabel.height/2
PathLine{
x: 0 - linearLabel.width
y: rootWidget.height/2 - linearLabel.height/2
}
}
running: true
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/121527.html
標籤:C++ 語言
上一篇:流媒體協議轉換服務
下一篇:求助帖!!!
