如何在 QtQuick 2.0 上为 Rectangle
视觉项绘制阴影?
我喜欢为主窗口绘制阴影(我有一个透明且未装饰的窗口)
最佳答案
作为剪切阴影问题的解决方法,您可以将矩形
放入Item
中,并使用额外的边距来考虑模糊半径,并在其上应用阴影容器:
import QtQuick 2.0
import QtGraphicalEffects 1.0
Item {
width: 320
height: 240
Item {
id: container
anchors.centerIn: parent
width: rect.width + (2 * rectShadow.radius)
height: rect.height + (2 * rectShadow.radius)
visible: false
Rectangle {
id: rect
width: 100
height: 50
color: "orange"
radius: 7
antialiasing: true
border {
width: 2
color: "red"
}
anchors.centerIn: parent
}
}
DropShadow {
id: rectShadow
anchors.fill: source
cached: true
horizontalOffset: 3
verticalOffset: 3
radius: 8.0
samples: 16
color: "#80000000"
smooth: true
source: container
}
}
关于qt - 如何在 QtQuick 2.0 上为矩形创建阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15488714/