简体   繁体   English

将前景色添加到Iteml QML

[英]Adding foreground color to an Iteml QML

I have an item which I've turned into a button with animations based on different states.我有一个项目,我已经把它变成了一个带有基于不同状态的动画的按钮。 The problem is, sometimes that button will be disabled and then I want it to have a semi-transparent foreground color to basically shade it out and signify that the button is disabled.问题是,有时该按钮将被禁用,然后我希望它具有半透明的前景色,以基本上将其遮蔽并表示该按钮已禁用。 Is there a way to do that to a QML Item?有没有办法对 QML 项目做到这一点?

If I understand your question correctly, you just need to add a Rectangle that is only visible if your button is disabled.如果我正确理解您的问题,您只需要添加一个仅在您的按钮被禁用时才可见的矩形。

Item {
    id: button

    Rectangle {
        anchors.fill: parent
        color: "red"
        opacity: 0.3
        z: 2   // <-- Make sure it stays on top of the rest of the content
        visible: !button.enabled
    }
}

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

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