如何防止模糊的QtGraphicalEffects被切断?

cgm*_*gmb 6 qt qml qt-quick

带有截止阴影的qml窗口

我正在尝试使用带有QtGraphicalEffects的QtQuick 2为我的项目添加效果,但我不太明白如何调整真正模糊的效果来看起来正确.

在这种情况下,投影的尺寸很小,并且在完全消失之前会在边缘处被剪裁.我怎样才能让它很好地融入而不会被切断?

这是窗口的代码:

import QtQuick 2.0
import QtGraphicalEffects 1.0

Item {
    width: 250
    height: 75

    Text {
        id: textItem
        x: 10; y: 10
        text: "how can I fix my shadow?"
    }

    DropShadow {
        id: shadowEffect
        anchors.fill: textItem
        source: textItem

        radius: 8
        samples: 16

        horizontalOffset: 20
        verticalOffset: 20
    }
}
Run Code Online (Sandbox Code Playgroud)

The*_*roo 8

你必须允许原始项目(将由效果复制)周围有足够的空间,以允许完全绘制效果,我会做这样的事情:

import QtQuick 2.0
import QtGraphicalEffects 1.0

Item {
    width: 320;
    height: 240;

    Text {
        id: textItem;
        anchors.centerIn: parent;
        text: "how can I fix my shadow?";

        /* extend the bounding rect to make room for the shadow */
        height: paintedHeight + (shadowEffect.radius * 2);
        width: paintedWidth + (shadowEffect.radius * 2);

        /* center the text to have space on each side of the characters */
        horizontalAlignment: Text.AlignHCenter;
        verticalAlignment: Text.AlignVCenter;

        /* hide the original item because the Graphical Effect duplicates it anyway */
        visible: false;
    }
    DropShadow {
        id: shadowEffect;
        anchors.fill: source;
        source: textItem;
        radius: 8;
        samples: 16;
        horizontalOffset: 20;
        verticalOffset: 20;
    }
}
Run Code Online (Sandbox Code Playgroud)