【发布时间】:2014-12-15 13:04:49
【问题描述】:
如何在 QML 中实现带有内阴影的矩形?
请参阅以下链接中的示例:
更新:
这是我正在尝试做的简化版本(不显示任何阴影):
import QtQuick 2.0
import QtGraphicalEffects 1.0
Item {
width: 400
height: 400
Item {
anchors.fill: parent
Rectangle {
id: myRectangle
anchors.centerIn: parent
width: 200
height: 200
color: "grey"
}
}
InnerShadow {
anchors.fill: myRectangle
cached: true
visible: true
horizontalOffset: 0
verticalOffset: 0
radius: 25
samples: 16
color: "#b0000000"
smooth: true
source: myRectangle
}
}
对不起。我的愚蠢......当我简化代码时我弄错了(该项目用于 DropShadow 测试,它有效)。 这就是它应该的样子:
import QtQuick 2.0
import QtGraphicalEffects 1.0
Item {
width: 400
height: 400
Rectangle {
id: myRectangle
anchors.centerIn: parent
width: 200
height: 200
color: "grey"
}
InnerShadow {
anchors.fill: myRectangle
cached: true
visible: true
horizontalOffset: 0
verticalOffset: 0
radius: 25
samples: 16
color: "#b0000000"
smooth: true
source: myRectangle
}
}
【问题讨论】:
-
锚点不适用于非父母或兄弟姐妹的项目,因此请尝试将
InnerShadow移动到您的Item。 -
@cmannett85 是对的。您没有看到任何警告/错误吗?在这种情况下,内部项目变得毫无意义。
-
Moving inside
myRectangleis not an options as for the documentation ofsourceproperty --> "注意:不支持让效果包含自身,例如通过将源设置为效果的父级。”