一、效果
![](https://img8.php1.cn/3cdc5/188e2/b64/998e44a4aa7eb6a3.gif)
二、代码
import QtQuick 2.0
import QtQuick.Controls 2.15Rectangle {width: 600height: 200property int recWidth: 250Rectangle {id: innnerRecwidth: recWidthheight: 50anchors.centerIn: parentcolor: "beige"// 子元素超出该项目的范围时,将被裁减clip: trueText {id: textInfoanchors.verticalCenter: parent.verticalCenterfont.pixelSize: 20text: qsTr("进入环岛图标,右侧通行地区的逆时针环岛")Component.onCompleted: animScroll.running = true}// 顺序动画SequentialAnimation {id: animScroll// 循环次数:极大的loops: Animation.InfinitePropertyAnimation {target: textInfoproperty: "x"from: 0to: -(textInfo.width)duration: (textInfo.width) * 30}PropertyAnimation {target: textInfoproperty: "x"from: recWidthto: 0duration: recWidth * 30}}}Button {anchors.top: innnerRec.bottomanchors.topMargin: 10anchors.horizontalCenter: parent.horizontalCentertext: "stop"onClicked: {text === "start" ? text = "stop" : text = "start"}onTextChanged: text === "stop" ? animScroll.running = true : animScroll.running = false}
}
三、注意