RollTextStyle.qml
import QtQuick 2.4
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 1.3
import QtQuick.Controls.Private 1.0
Style{
id:rollTextStyle
property RollText control: __control
property Component rollText:Text {
id:rt
text: control.text
property bool rollFlag :true
property bool rollStart: false
PropertyAnimation on x{
id:leftRoll
to:parent.x-rollfunc()
duration: 2000
easing.type: Easing.Linear
}
PropertyAnimation on x{
id:rightRoll
to:parent.x+rollfunc()
duration: 2000
easing.type: Easing.Linear
}
Timer{
interval: 2000
running: true
repeat: true
onTriggered: {
if(control.running === true && rt.rollFlag === true)
{
rt.rollFlag = false
rightRoll.start()
}
else if(control.running === true && rt.rollFlag === false)
{
rt.rollFlag = true
leftRoll.start()
}
}
}
function rollfunc(){
if(rt.rollStart === false)
{
rt.rollStart = true
return 50
}
else
{
return 100
}
}
}
property Component panel: Item {
implicitWidth: rollLoader.implicitWidth
implicitHeight: rollLoader.implicitHeight
Loader{
id:rollLoader
sourceComponent: rollText
anchors.fill: parent
width: 160
height: 40
}
}
}
RollText.qml
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Controls.Private 1.0
Control{
id:rollText
implicitWidth: 160
implicitHeight: 40
property string text:qsTr("test")
property bool running: false
style:Settings.styleComponent(Settings.style, "RollText.qml", rollText)
}
这个控件可以实现一个Text向左向右移动