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 make round imageas
Forum Updated to NodeBB v4.3 + New Features

How to make round imageas

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 405 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.
  • K Offline
    K Offline
    Kiovtorov
    wrote on last edited by
    #1

    I can't seem to find how to make a round Image.
    I tried using a mask which didn't work

       Rectangle
                                        {
                                            id: mask
                                            anchors.left: parent.left
                                            anchors.leftMargin: 15
                                            width: 50
                                            height: 50
                                            radius:25
                                            clip: true
    
                                        }
    
                                        Image {
                                            id: storeIcon
                                           anchors.fill: mask
                                            source: model.source
    
                                        }
    

    Some said to use ShaderEffectSource in 2011 but that also didn't work out since qt designer studio couldn't find the import. Am I missing a method?

    J.HilkJ 1 Reply Last reply
    0
    • MarkkyboyM Markkyboy

      @Kiovtorov - take a look at an example directly from Qt; https://doc.qt.io/qt-5/qml-qtgraphicaleffects-opacitymask.html - I think you'll better understand the layout of the code and see what you're missing code wise.

      K Offline
      K Offline
      Kiovtorov
      wrote on last edited by
      #5

      @Markkyboy
      The whole problem with OpacityMask was QtGraphicalEffects since it is not included in Qt6 but I in a forum I found import Qt5Compat.GraphicalEffects and it now works like following:

      Rectangle {
                                                  id: mask
                                                  anchors.left: parent.left
                                                  anchors.leftMargin: 15
                                                  width: 50
                                                  height: 50
                                                  radius: 25
                                                  clip: true
                                              }
      
                                              Image {
                                                  id: storeIcon
                                                  anchors.fill: mask
                                                  source: "qrc:/image.png"
                                                  fillMode: Image.PreserveAspectCrop
                                                          layer.enabled: true
                                                          layer.effect: OpacityMask {
                                                              maskSource: mask
                                                          }
                                              }
      
      1 Reply Last reply
      0
      • K Kiovtorov

        I can't seem to find how to make a round Image.
        I tried using a mask which didn't work

           Rectangle
                                            {
                                                id: mask
                                                anchors.left: parent.left
                                                anchors.leftMargin: 15
                                                width: 50
                                                height: 50
                                                radius:25
                                                clip: true
        
                                            }
        
                                            Image {
                                                id: storeIcon
                                               anchors.fill: mask
                                                source: model.source
        
                                            }
        

        Some said to use ShaderEffectSource in 2011 but that also didn't work out since qt designer studio couldn't find the import. Am I missing a method?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @Kiovtorov move the Image inside the scope of mask. make it a child, not a sibling.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kiovtorov
          wrote on last edited by
          #3

          If you meant the structure to be like the following

          Rectangle
                                              {
                                                  id: mask
                                                  anchors.left: parent.left
                                                  anchors.leftMargin: 15
                                                  width: 50
                                                  height: 50
                                                  radius:25
                                                  clip: true
                                                  Image {
                                                      id: storeIcon
                                                     anchors.fill: mask
                                                      source: model.source
          
                                                  }
                                              }
          

          it didn't work

          1 Reply Last reply
          0
          • MarkkyboyM Offline
            MarkkyboyM Offline
            Markkyboy
            wrote on last edited by
            #4

            @Kiovtorov - take a look at an example directly from Qt; https://doc.qt.io/qt-5/qml-qtgraphicaleffects-opacitymask.html - I think you'll better understand the layout of the code and see what you're missing code wise.

            Don't just sit there standing around, pick up a shovel and sweep up!

            I live by the sea, not in it.

            K 1 Reply Last reply
            0
            • MarkkyboyM Markkyboy

              @Kiovtorov - take a look at an example directly from Qt; https://doc.qt.io/qt-5/qml-qtgraphicaleffects-opacitymask.html - I think you'll better understand the layout of the code and see what you're missing code wise.

              K Offline
              K Offline
              Kiovtorov
              wrote on last edited by
              #5

              @Markkyboy
              The whole problem with OpacityMask was QtGraphicalEffects since it is not included in Qt6 but I in a forum I found import Qt5Compat.GraphicalEffects and it now works like following:

              Rectangle {
                                                          id: mask
                                                          anchors.left: parent.left
                                                          anchors.leftMargin: 15
                                                          width: 50
                                                          height: 50
                                                          radius: 25
                                                          clip: true
                                                      }
              
                                                      Image {
                                                          id: storeIcon
                                                          anchors.fill: mask
                                                          source: "qrc:/image.png"
                                                          fillMode: Image.PreserveAspectCrop
                                                                  layer.enabled: true
                                                                  layer.effect: OpacityMask {
                                                                      maskSource: mask
                                                                  }
                                                      }
              
              1 Reply Last reply
              0
              • K Kiovtorov has marked this topic as solved on

              • Login

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