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. Why radius no effect when clip: true for Rectangle
Forum Updated to NodeBB v4.3 + New Features

Why radius no effect when clip: true for Rectangle

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 282 Views
  • 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.
  • R Offline
    R Offline
    RoyDut
    wrote last edited by RoyDut
    #1

    I want to use a rec to clip a given image, but no change when set radius: 20. Could anyone please help?```

    Item {
            id: electricity
    
            property real value: 0.7  // 0.0 ~ 1.0
    
            Image {
                x: 535
                y: 73
                width: 30
                height: 329
                source: "qrc:/Qml/New/Image/electricity_border.png"
            }
    
            Item {
                id: container2
                x: 539
                y: 79
                width: 22
                height: 317
            }
    
            Rectangle {
                id: clipper2
                width: 22
                height: 317 * electricity.value
                anchors.left: container2.left
                anchors.bottom: container2.bottom
                radius: 20
                clip: true
    
                Behavior on height {
                    SpringAnimation {
                        spring: 0.7; damping:0.1; mass:0.2; epsilon:0.25
                    }
                }
    
                Image {
                    source: "qrc:/Qml/New/Image/electricity.png"
                    width: 22
                    height: 317
                    anchors.bottom: parent.bottom
                    anchors.left: parent.left
                }
            }
        }
    
    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vitalii777
      wrote last edited by
      #2

      Please try to set mask like said here:
      https://forum.qt.io/topic/145956/rounded-image-in-qt6/10

      There are different ways to do this depending from Qt version you use.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SuhasKrishanamurthy
        wrote last edited by
        #3
        Item {
            id: electricity
        
            property real value: 0.7  // 0.0 ~ 1.0
        
            Image {
                x: 535
                y: 73
                width: 30
                height: 329
                source: "qrc:/Qml/New/Image/electricity_border.png"
            }
        
            Item {
                id: container2
                x: 539
                y: 79
                width: 22
                height: 317
            }
        
            Item {
                id: clipper2
                width: 22
                height: 317 * electricity.value
                anchors.left: container2.left
                anchors.bottom: container2.bottom
        
                layer.enabled: true
                layer.effect: OpacityMask {
                    maskSource: Rectangle {
                        width: clipper2.width
                        height: clipper2.height
                        radius: 20
                        color: "white"
                    }
                }
        
                Behavior on height {
                    SpringAnimation {
                        spring: 0.7; damping: 0.1; mass: 0.2; epsilon: 0.25
                    }
                }
        
                Image {
                    source: "qrc:/Qml/New/Image/electricity.png"
                    width: 22
                    height: 317
                    anchors.bottom: parent.bottom
                    anchors.left: parent.left
                }
            }
        }
        
        
        1 Reply Last reply
        0
        • R Offline
          R Offline
          RoyDut
          wrote last edited by
          #4

          Thank you Vitalii777 and SuhasKrishanamurthy for your help. Much appreciated!
          The code above working good.

          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