要实现的效果如下:

代码:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0
Window {
visible: true
width: 400
height: 100
title: qsTr("Hello World")
Text{
id: mt
anchors.centerIn: parent
visible: false
color: "red"
text:"曾经年少爱追梦,一心只想往前飞。"
font.pixelSize: 24
}
PropertyAnimation{
target: mr1
property: "width"
from: 0
to: m2.width
duration: 5000
loops: -1
running: true
}
Rectangle{
id: m2
anchors.fill: mt
color:"#00000000"
Rectangle{
id: mr1
height:parent.height
color: "blue"
//width是从0到m2.width
}
Rectangle{
x: mr1.width //从0到m2.width
height:parent.height
width: m2.width-mr1.width
color: "red"
}
}
ShaderEffectSource {
id: mask
visible: false
anchors.fill: mt
hideSource : true
sourceItem: m2
}
Blend {
anchors.fill: mt
source: mt
foregroundSource: mask
mode: "color"
}
}
参考:
https://blog.youkuaiyun.com/zcwwcw/article/details/38726067
https://blog.youkuaiyun.com/willspace/article/details/48683897
https://www.jianshu.com/p/85f04a2fc030
300



被折叠的 条评论
为什么被折叠?



