【问题标题】:Blur background in QML在 QML 中模糊背景
【发布时间】:2021-12-06 00:22:39
【问题描述】:

我不知道如何模糊窗口的背景(类似于 CSS 中的 backdrop-filter: blur)。

显然我必须使用名为 ShaderEffect 的东西,但我不知道如何编写着色器。

我找到了以下高斯模糊代码,我认为它是合适的,但我如何将它放入我的项目中?

https://www.shadertoy.com/view/Xltfzj

我想要这样的图片:

【问题讨论】:

标签: qt qml shader gaussianblur qt6


【解决方案1】:

这实际上不是一件容易的事情,因为您不希望您的模糊对象成为将被模糊的项目的子项。否则它将试图模糊自己。这里有一些东西可以让你大致了解一下。

Item {
    id: window

    Image {
         id: background
         anchors.fill: parent
         source: "someImg.jpg"
    }

    // This can't be a child of `background`
    Item {
        id: clipRect
        anchors.centerIn: parent
        width: 300
        height: 300
        clip: true

        // We want the blur object to fill the background 
        // but be clipped to its parent
        FastBlur {
            x: -parent.x
            y: -parent.y
            width: background.width
            height: background.height
            source: background
            radius: 64
        }

        // Just to put a border around the blur
        Rectangle {
            anchors.fill: parent
            color: "transparent"
            border.color: "orange"
            border.width: 2
        }
    }
}

【讨论】:

    【解决方案2】:

    如果你想在 CSS 中对图片进行模糊处理,你需要转到图片或类的样式并进行过滤:blur(radius);

    半径是您希望模糊的大小。你必须记住在半径后面加上'px',例如 filter: blur(8px);

    你也可以把它作为rem而不是px。关于您提供的链接的快速说明:它不是 CSS 语言。您不一定需要着色器效果才能工作。

    如果您确实想使用着色器,请等待其他人的回复:)

    【讨论】:

    • 我不想在 CSS 中这样做...我想要在 Qt 中实现这种模糊效果。这就是为什么 qtqt6qml 在标签中。
    • CSS?先生,我们这里不这样做!
    猜你喜欢
    • 1970-01-01
    • 2022-12-10
    • 2018-04-24
    • 2019-07-03
    • 2021-01-15
    • 2017-07-17
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    相关资源
    最近更新 更多