简体   繁体   English

QML动画从底部到顶部过渡颜色

[英]QML Animation to transition color from bottom to top

I have a login QML page. 我有一个登录QML页面。 When the user inputs the code, I have 4 circles in white, and I would like to transition to blue, filling the circle from bottom to top. 当用户输入代码时,我有4个白色圆圈,我想转换为蓝色,从下到上填充圆圈。

So basically, I want to animate the color property so it transitions from white to blue when "isNumberInserted" is true, and just move it back to white without any transition when the user clears PIN (isNumberInserted = false). 所以基本上,我想设置颜色属性的动画,以便当“isNumberInserted”为真时它从白色转换为蓝色,并在用户清除PIN(isNumberInserted = false)时将其移回白色而不进行任何转换。

Rectangle{
    anchors.centerIn: parent;
    width: 100; height: width; radius: width/2
    color: isNumberInserted ? "blue" : "white"
}

Any ideas? 有任何想法吗? Thanks! 谢谢!


Update:: SOLUTION: Based on the reply (thanks!), it goes like this: 更新::解决方案:根据回复(谢谢!),它是这样的:

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" }
    }
}

You can abuse a gradient and a property to prescribe the gradient-stops: 你可以滥用渐变和属性来规定渐变 - 停止:

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" }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM