gpt4 book ai didi

QML矩形不透明度只有颜色

转载 作者:行者123 更新时间:2023-12-01 09:23:18 32 4
gpt4 key购买 nike

我只想在我的矩形上设置不透明度。但文字也变得透明。
我怎么能只设置背景。

Rectangle {
id: button
color: "black"
opacity: 0.3
width: parent.width
height: 35

Text {
anchors.centerIn: parent
text: qsTr("text")
color: "white"
font.pixelSize: 25
}
}

最佳答案

这在 documentation for opacity 中有解释:

When this property is set, the specified opacity is also applied individually to child items. This may have an unintended effect in some circumstances. For example in the second set of rectangles below, the red rectangle has specified an opacity of 0.5, which affects the opacity of its blue child rectangle even though the child has not specified an opacity.



您可以移动 Text项目出:
Rectangle {
id: button
color: "black"
opacity: 0.3
width: parent.width
height: 35
}

Text {
anchors.centerIn: button
text: qsTr("text")
color: "white"
font.pixelSize: 25
}

或者给 Rectangle透明颜色而不是改变不透明度:
Rectangle {
id: button
color: "#33000000" // form: #AARRGGBB
width: parent.width
height: 35

Text {
anchors.centerIn: parent
text: qsTr("text")
color: "white"
font.pixelSize: 25
}
}

关于QML矩形不透明度只有颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26364676/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com