javascript - QML Shader Effect blur behind an item - Stack Overflow

Is it possible to make a blur of an item which is behind another item?Example: blur a part of image (li

Is it possible to make a blur of an item which is behind another item?

Example: blur a part of image (like in qml - parent.centerIn: image)

I want something like:

Image { id: img
    anchors.fill: parent
    source: "bug.png"

    Item { id: info
        anchors.centerIn: parent
        height: 200
        width: 200

        Text {
            text: "HAMMER TIME"
            color: "white"
        }

        /* BLUR CODE HERE TO BLUR BACKGROUND OF THIS ITEM */
        /* which is a part of "bug.png" image with 200x200 size */
        /* and offset equals to "info.x" and "info.y" */
    }
}

This question affects any shader effect because official docs dont have an answer for the question and all of my attempts are unsuccessfull - it is only possible to blur WHOLE ITEM but not a part of it.

Is it possible to make a blur of an item which is behind another item?

Example: blur a part of image (like in qml - parent.centerIn: image)

I want something like:

Image { id: img
    anchors.fill: parent
    source: "bug.png"

    Item { id: info
        anchors.centerIn: parent
        height: 200
        width: 200

        Text {
            text: "HAMMER TIME"
            color: "white"
        }

        /* BLUR CODE HERE TO BLUR BACKGROUND OF THIS ITEM */
        /* which is a part of "bug.png" image with 200x200 size */
        /* and offset equals to "info.x" and "info.y" */
    }
}

This question affects any shader effect because official docs dont have an answer for the question and all of my attempts are unsuccessfull - it is only possible to blur WHOLE ITEM but not a part of it.

Share Improve this question edited Jan 19, 2015 at 19:46 VP. asked Jan 19, 2015 at 19:41 VP.VP. 16.8k20 gold badges106 silver badges172 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

Here is my solution. This version is just applicable to Rectangles. The Item ShaderEffectSource helps with creating such a source rectangle.

import QtQuick 2.3
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0

Window {
    visible: true
    width: 600
    height:600

    Image {
        id: image_bug

        anchors.fill: parent
        source: "images/Original_bug.png"
    }

    ShaderEffectSource {
        id: effectSource

        sourceItem: image_bug
        anchors.centerIn: image_bug
        width: 400
        height: 400
        sourceRect: Qt.rect(x,y, width, height)
    }

    FastBlur{
        id: blur
        anchors.fill: effectSource

        source: effectSource
        radius: 100
    }
}

If you need other shapes, I think you might need to apply a mask-shader, cutting out the relevant parts first and then apply the blur.

Not the prettiest solution but I afraid there is no such Qml mechanism.
You could apply on your image second image with same source and clip it to your needs, like below:

Image {
    id: img
    anchors.fill: parent
    source: "bug.png"

    Item { id: info
        anchors.centerIn: parent
        height: 200
        width: 200

    Text {
        text: "HAMMER TIME"
        color: "white"
    }

    /* BLUR CODE HERE TO BLUR BACKGROUND OF THIS ITEM */
    /* which is a part of "bug.png" image with 200x200 size */
    /* and offset equals to "info.x" and "info.y" */

    clip:true
    Image {
        id: img2
        x: -info.x
        y: -info.y
        width: img.width
        height: img.height
        source: img.source
    }
    FastBlur {
        anchors.fill: img2
        source: img2
        radius: 32
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743759124a4502297.html

相关推荐

  • javascript - QML Shader Effect blur behind an item - Stack Overflow

    Is it possible to make a blur of an item which is behind another item?Example: blur a part of image (li

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信