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. ColorOverlay disappears when scaled
Forum Updated to NodeBB v4.3 + New Features

ColorOverlay disappears when scaled

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
dropshadowscaleoverlay
3 Posts 2 Posters 1.7k 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.
  • J Offline
    J Offline
    jars121
    wrote on 16 Jan 2018, 04:18 last edited by
    #1

    Hi,

    I have a ColorOverlay on an image, which changes the colour of the image depending on runtime parameters. This works nicely :)

    When the user touches the image, the image scales slightly, and also has a DropShadow appear underneath to give the effect of the image/button raising slightly off the screen.

    The above works, except the ColorOverlay appears to stop working as soon as the scale is changed. I.e. the original image is shown rather than the ColorOverlay image.

    Image {
        id: image1
           x: 10
           y: 10
           width: 100
           height: 100
           source: Qt.resolvedUrl("Images/Image.svg")
           visible: false
    }
    
    ColorOverlay{
        id: colorOverlay1
        anchors.fill: image1
        source: image1
        color: "red"
        antialiasing: true
        scale: mouseArea1.pressed ? 1.02:1.0
    
        MouseArea {
            id: mouseArea1
            anchors.fill: parent
        }
    
        DropShadow {
            anchors.fill: colorOverlay1
            horizontalOffset: 2
            verticalOffset: 2
            radius: 12
            samples: 25
            color: "#aa000000"
            source: image1
            visible: mouseArea1.pressed ? true:false
        }
    
        Behavior on scale {
            NumberAnimation {duration: 200}
        }
    }
    

    In the example above, the image is red (indicating the ColorOverlay is working) until I press the image, at which point it scales slightly, the drop shadow appears, but the image returns to its normal colour (i.e. the 'red' disappears).

    What am I missing here?

    R 1 Reply Last reply 16 Jan 2018, 08:13
    0
    • J jars121
      16 Jan 2018, 04:18

      Hi,

      I have a ColorOverlay on an image, which changes the colour of the image depending on runtime parameters. This works nicely :)

      When the user touches the image, the image scales slightly, and also has a DropShadow appear underneath to give the effect of the image/button raising slightly off the screen.

      The above works, except the ColorOverlay appears to stop working as soon as the scale is changed. I.e. the original image is shown rather than the ColorOverlay image.

      Image {
          id: image1
             x: 10
             y: 10
             width: 100
             height: 100
             source: Qt.resolvedUrl("Images/Image.svg")
             visible: false
      }
      
      ColorOverlay{
          id: colorOverlay1
          anchors.fill: image1
          source: image1
          color: "red"
          antialiasing: true
          scale: mouseArea1.pressed ? 1.02:1.0
      
          MouseArea {
              id: mouseArea1
              anchors.fill: parent
          }
      
          DropShadow {
              anchors.fill: colorOverlay1
              horizontalOffset: 2
              verticalOffset: 2
              radius: 12
              samples: 25
              color: "#aa000000"
              source: image1
              visible: mouseArea1.pressed ? true:false
          }
      
          Behavior on scale {
              NumberAnimation {duration: 200}
          }
      }
      

      In the example above, the image is red (indicating the ColorOverlay is working) until I press the image, at which point it scales slightly, the drop shadow appears, but the image returns to its normal colour (i.e. the 'red' disappears).

      What am I missing here?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 16 Jan 2018, 08:13 last edited by
      #2

      @jars121
      if i got you right, i think this does what you want:

      Item {
          Image {
              id: image1
              x: 10
              y: 10
              width: 200
              height: 200
              fillMode: Image.PreserveAspectFit
              source: "file:///C:/test.png"
              visible: false
          }
      
          ColorOverlay {
              id: colorOverlay1
              anchors.fill: image1
              source: image1
              color: "red"
              antialiasing: true
              visible: mouseArea1.pressed ? false:true
      
              scale: mouseArea1.pressed ? 1.02 : 1.0
              transformOrigin: Item.Center
      
              Behavior on scale {
                  NumberAnimation {duration: 200}
              }
          }
      
          DropShadow {
              anchors.fill: colorOverlay1
              horizontalOffset: 2
              verticalOffset: 2
              radius: 12
              samples: 25
              color: "#aa000000"
              source: colorOverlay1
              visible: mouseArea1.pressed ? true:false
              antialiasing: true
      
              scale: mouseArea1.pressed ? 1.02 : 1.0
              transformOrigin: Item.Center
      
              Behavior on scale {
                  NumberAnimation {duration: 200}
              }
          }
      
          MouseArea {
              id: mouseArea1
              anchors.fill: image1
          }
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • J Offline
        J Offline
        jars121
        wrote on 17 Jan 2018, 06:36 last edited by jars121
        #3

        Thanks for your reply.

        This seems to have improved the situation somewhat, as I can now see the red image when I click. However, the original image seems to be overlayed over the top of the red image with a level of transparency. It's almost like the visible: false parameter is changed when the MouseArea is clicked?

        It's somewhat hard to explain, hopefully the above makes sense?

        If not, I can put together some screenshots to demonstrate the issue?

        EDIT: Never mind, it looks like user error after all! I had the z-order configured incorrectly, so the drop shadow was being drawn on top of the image rather than underneath it. Thanks again for your help!

        1 Reply Last reply
        0

        2/3

        16 Jan 2018, 08:13

        • Login

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