Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a gradient opacity in an image?

How do I make an image fade in qml? How do I achieve this effect? here I attach the image of how I want it to look

enter image description here

like image 391
Samir Llorente Avatar asked Sep 07 '25 14:09

Samir Llorente


1 Answers

A possible solution is to use OpacityMask with a LinearGradient as source

import QtQuick 2.9
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0

Window {
    visible: true
    width: 600
    height: 600
    title: qsTr("Hello World")
    Image {
        id: input
        source: "input.jpg"
        anchors.fill: parent

        OpacityMask {
            source: mask
            maskSource: input
        }

        LinearGradient {
            id: mask
            anchors.fill: parent
            gradient: Gradient {
                GradientStop { position: 0.2; color: "transparent"}
                GradientStop { position: 0.5; color: "white" }
            }
        }
    }
}

Input:

enter image description here

Output:

enter image description here

like image 124
eyllanesc Avatar answered Sep 10 '25 06:09

eyllanesc