Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML LinearGradient console log warning



  • Hi, i'm trying to add a linear gradient to a rectangle. But in doing so i get he following console log: ShaderEffectSource: 'recursive' must be set to true when rendering recursively.

    Simple question why do i have to put my linear gradient like this:

    Rectangle{
            id: mainRec
            width: parent.width - 15
            height: parent.height - 18
            anchors.centerIn: parent
            radius: 25
        }
    
        LinearGradient{
            anchors.fill: mainRec
            source: mainRec
            start: Qt.point(0, 0)
            end: Qt.point(mainRec.width, mainRec.height)
            gradient: Gradient {
                GradientStop { position: 0.0; color: "#3B4567" }
                GradientStop { position: 1.0; color: "black" }
            }
        }
    

    instead of:

    Rectangle{
            id: mainRec
            width: parent.width - 15
            height: parent.height - 18
            anchors.centerIn: parent
            radius: 25
            
            LinearGradient{
                anchors.fill: parent
                source: parent
                start: Qt.point(0, 0)
                end: Qt.point(parent.width, parent.height)
                gradient: Gradient {
                    GradientStop { position: 0.0; color: "#3B4567" }
                    GradientStop { position: 1.0; color: "black" }
                }
            }
        }
    

    to avoid the warning mentioned above? Although i'm getting the correct result when adding later more items inside the rectangle i have to do that outside mainRec brackets which i'm not supposed to because that one has to be the main parent.


  • Moderators

    @onimusha
    The LinearGradient element takes the source element for rendering. So if you put the LinearGradient element as a child of that source element it would render itself recursively, as the warning message says.



  • @raven-worx Oh i see, thanks, plus i just came across this in the docs Note: It is not supported to let the effect include itself, for instance by setting source to the effect's parent. so that explains why.


Log in to reply