You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

QML自定义Shape无法应用DropShadow阴影,Rectangle可正常生效,该如何解决?

QML Shape组件无法显示DropShadow阴影的解决办法

问题出在DropShadow的工作机制上:它需要依赖目标组件的**图层渲染(Layer)**来捕获绘制内容。Rectangle组件默认具备可被阴影效果捕获的渲染上下文,但Shape组件得手动开启图层功能,才能让DropShadow识别到它的绘制内容。

解决方法很简单,给Shape组件添加layer.enabled: true属性即可:

Shape { 
    id: shape
    layer.enabled: true // 开启图层渲染,让DropShadow能捕获Shape的绘制内容
    ShapePath {
        // 此处填写你的路径定义
        fillColor: "blue"
    }
}
DropShadow {
    anchors.fill: shape
    radius: 50
    samples: 20
    horizontalOffset: 5
    verticalOffset: 5
    color: "red"
    source: shape
}

如果Shape的路径包含透明区域,DropShadow会自动识别并仅对非透明部分生成阴影,完全符合预期效果。

内容的提问来源于stack exchange,提问作者Dragoș Radu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 20:17:15