本文共 1539 字,大约阅读时间需要 5 分钟。
加载对应的组件QtGraphicalEffects。
import QtGraphicalEffects 1.0
cached : 是否需要缓存,默认为false,如果设置为True,则占用内存color : 阴影对应的颜色,默认为blackhorizontalOffset : 阴影在水平方向的偏移,-10代表往左边偏移10像素,10代表往右偏移10像素radius : 阴影边缘模糊的半径,默认为0samples : 此属性定义在执行边缘软化模糊计算时,每个像素采集的采样数。值越大,质量越好,但渲染速度越慢。source : 源组件spread : 阴影边缘的扩散,值越大,扩散越大transparentBorder : 边缘是否透明处理verticalOffset : 竖直阴影的偏移
方法一,在Item中,DropShadow和源组件并列,通过source和anchors与源组件关联。
import QtQuick 2.12 import QtGraphicalEffects 1.12 Item { width: 300 height: 300 Rectangle { anchors.fill: parent } Image { id: butterfly source: "images/butterfly.png" sourceSize: Qt.size(parent.width, parent.height) smooth: true visible: false } DropShadow { anchors.fill: butterfly horizontalOffset: 3 verticalOffset: 3 radius: 8.0 samples: 17 color: "#80000000" source: butterfly } }
方法一,在Rectangle中,DropShadow作为layer.effect的属性值,直接与Rectangle关联。
Rectangle { id:showWin visible: true width:100 height: 100 x: (parent.width - width)/2 y: (parent.height - height)/2 color: color_SSMAN_GRAY radius: 10 layer.enabled: true // 设置layer为enable layer.effect: DropShadow { transparentBorder: true color: "black" samples:100 } }
3.1 color
2、horizontalOffset 3、radius 4、Spread转载地址:http://dxuun.baihongyu.com/