Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to use ColorOverlay on item in layout?

How to use ColorOverlay on item in layout?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlexP11223
    wrote on last edited by
    #1

    I have a RowLayout with some items

    RowLayout {
        anchors.fill: parent
        anchors.leftMargin: 3
    
        Image {
            id: icon
            source: imgSource
            sourceSize: Qt.size(parent.width, parent.height)
            smooth: true
        }
    
        Text {
            id: caption
            height: parent.height
            fontSizeMode: Text.Fit
            font.pointSize: textSize
            verticalAlignment: Text.AlignVCenter
            text: captionText
            color: "white"
        }
    } 
    

    and I want to apply ColorOverlay on Image inside this layout:

    ColorOverlay {
        id: overlay
        anchors.fill: icon
        source: icon
        color: "#ff0000ff"
    }
    

    But if I put ColorOverlay outside of the layout, then I can't use anchors.fill: icon. And if I make it a child

        Image {
            id: icon
            source: imgSource
            sourceSize: Qt.size(parent.width, parent.height)
            smooth: true  
            ColorOverlay {
                id: overlay
                anchors.fill: icon
                source: icon
                color: "#ff0000ff"
            }
        }
    

    it seems to work but I get warnings in console ShaderEffectSource: 'recursive' must be set to true when rendering recursively.

    1 Reply Last reply
    0
    • Y Yaswanth

      @AlexP11223 If you want to use anchors only to fill, you can specify width & height explicitly for the ColorOverlay . I can not run the above code as I don't have latest Qt version.

      A Offline
      A Offline
      AlexP11223
      wrote on last edited by
      #6

      @Yaswanth I would also need x and y, but I tried and the position was a bit wrong, probably because of some margins.

      Anyway, I solved it using layers: https://stackoverflow.com/a/52811823/964478

      Image {
          source: imgSource
          sourceSize: Qt.size(parent.width, parent.height)
          smooth: true  
          layer {
              enabled: true
              effect: ColorOverlay {
                  color: "#ff0000ff"
              }
          }
      }
      
      1 Reply Last reply
      0
      • 6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by
        #2

        @AlexP11223 said in How to use ColorOverlay on item in layout?:

        ColorOverlay

        What about an Item containing both as: https://forum.qt.io/topic/72501/coloroverlay-in-gridlayout/7

        Looks like that might work for you. I'd fire up a test if I had a little more time... might get you moving though.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          Yaswanth
          wrote on last edited by Yaswanth
          #3

          If you want to access the element in the RowLayout, specify an id for RowLayout and create alias for the Image,

          RowLayout {
          id : rowLayout
          property var imageIcon : icon
              anchors.fill: parent
              anchors.leftMargin: 3
          
              Image {
                  id: icon
                  source: imgSource
                  sourceSize: Qt.size(parent.width, parent.height)
                  smooth: true
              }
          //Some code
          }
          ColorOverlay {
              id: overlay
              anchors.fill: rowLayout.imageIcon 
              source: rowLayout.imageIcon 
              color: "#ff0000ff"
          }
          
          A 1 Reply Last reply
          0
          • Y Yaswanth

            If you want to access the element in the RowLayout, specify an id for RowLayout and create alias for the Image,

            RowLayout {
            id : rowLayout
            property var imageIcon : icon
                anchors.fill: parent
                anchors.leftMargin: 3
            
                Image {
                    id: icon
                    source: imgSource
                    sourceSize: Qt.size(parent.width, parent.height)
                    smooth: true
                }
            //Some code
            }
            ColorOverlay {
                id: overlay
                anchors.fill: rowLayout.imageIcon 
                source: rowLayout.imageIcon 
                color: "#ff0000ff"
            }
            
            A Offline
            A Offline
            AlexP11223
            wrote on last edited by
            #4

            @Yaswanth it's not about accessing, anchors work only for siblings and parent http://doc.qt.io/qt-5/qtquick-positioning-anchors.html#restrictions (and if I make it a child it works but I get that warning about rendering each time I change color).

            Y 1 Reply Last reply
            0
            • A AlexP11223

              @Yaswanth it's not about accessing, anchors work only for siblings and parent http://doc.qt.io/qt-5/qtquick-positioning-anchors.html#restrictions (and if I make it a child it works but I get that warning about rendering each time I change color).

              Y Offline
              Y Offline
              Yaswanth
              wrote on last edited by
              #5

              @AlexP11223 If you want to use anchors only to fill, you can specify width & height explicitly for the ColorOverlay . I can not run the above code as I don't have latest Qt version.

              A 1 Reply Last reply
              0
              • Y Yaswanth

                @AlexP11223 If you want to use anchors only to fill, you can specify width & height explicitly for the ColorOverlay . I can not run the above code as I don't have latest Qt version.

                A Offline
                A Offline
                AlexP11223
                wrote on last edited by
                #6

                @Yaswanth I would also need x and y, but I tried and the position was a bit wrong, probably because of some margins.

                Anyway, I solved it using layers: https://stackoverflow.com/a/52811823/964478

                Image {
                    source: imgSource
                    sourceSize: Qt.size(parent.width, parent.height)
                    smooth: true  
                    layer {
                        enabled: true
                        effect: ColorOverlay {
                            color: "#ff0000ff"
                        }
                    }
                }
                
                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved