QML矩形上的内部阴影

day*_*day 5 qt qml qt-quick qtquick2

如何在内部阴影的QML中实现Rectangle?

请参阅以下链接中的示例:

在UIView中创建内部阴影

更新:

这是我正在尝试做的简化版本(没有显示任何阴影):

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
   }
}
Run Code Online (Sandbox Code Playgroud)

对不起.我的愚蠢......当我简化代码时,我弄错了(该项用于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
   }
}
Run Code Online (Sandbox Code Playgroud)

Mit*_*tch 4

我不知道为什么,但如果您使用您尝试在其中投射阴影的项目上方的项目,它就会起作用(在这种情况下,它恰好是根项目,但不一定是):

import QtQuick 2.0
import QtGraphicalEffects 1.0

Item {
    id: root
    width: 300
    height: 300

    Rectangle {
        id: myRectangle
        anchors.centerIn: parent
        width: 100
        height: 100
        color: "grey"
    }

    InnerShadow {
        anchors.fill: root
        cached: true
        horizontalOffset: 0
        verticalOffset: 0
        radius: 16
        samples: 32
        color: "#b0000000"
        smooth: true
        source: root
    }
}
Run Code Online (Sandbox Code Playgroud)

内阴影截图

我在搜索相关 bug 时从QTBUG-27213中得到了这个想法。