qt - QML动画从底部到顶部过渡颜色
问题描述
我有一个登录 QML 页面。当用户输入代码时,我有 4 个白色圆圈,我想过渡到蓝色,从下到上填充圆圈。
所以基本上,我想为颜色属性设置动画,以便当“isNumberInserted”为真时它从白色过渡到蓝色,并且当用户清除 PIN 时将其移回白色而不进行任何过渡(isNumberInserted = false)。
Rectangle{
anchors.centerIn: parent;
width: 100; height: width; radius: width/2
color: isNumberInserted ? "blue" : "white"
}
有任何想法吗?谢谢!
更新:: 解决方案:根据回复(谢谢!),它是这样的:
Rectangle{
id: rect
anchors.centerIn: parent;
width: 100; height: width; radius: width/2
property double fillPosition: !isNumberInserted
Behavior on fillPosition {
enabled: !isNumberInserted
NumberAnimation { duration: 500 }
}
gradient: Gradient {
GradientStop { position: 0.0; color: "white" }
GradientStop { position: rect.fillPosition - 0.001; color: "white" }
GradientStop { position: rect.fillPosition + 0.001; color: "blue" }
GradientStop { position: 1.0; color: "blue" }
}
}
解决方案
您可以滥用梯度和属性来规定梯度停止:
Rectangle {
id: rect
anchors.centerIn: parent
width: 30
height: 30
radius: 15
color: "yellow"
property double fillPosition : 0.5
Behavior on fillPosition { NumberAnimation { duration: 500 } }
gradient: Gradient {
GradientStop { position: 0.0; color: "lightsteelblue" }
GradientStop { position: rect.fillPosition - 0.001; color: "lightsteelblue" }
GradientStop { position: rect.fillPosition + 0.001; color: "blue" }
GradientStop { position: 1.0; color: "blue" }
}
}
推荐阅读
- javascript - 如何在节点 Js 中获取呼叫者姓名
- python - 具有不同缩放参数的 Torch 优化器
- javascript - 如何从回调函数中捕获错误
- php - htmlentities
使用 PHPmailer 时忽略 - reactjs - 使用 useEffect 对状态变化做出反应
- json - 如何从 C3.ai COVID-19 数据湖中的 fetch API 将 fetch 返回对象转换为 csv?
- java - 仅通过父属性的 Java 子类等于父类
- haskell - Haskell 类型和值构造函数
- excel - 分配给形状的 Excel 宏可以格式化形状所在的单元格吗?
- laravel - 已解决:Laravel - 无法显示“提交表单”路线