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. Image inside a Rectangle ignores radius

Image inside a Rectangle ignores radius

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

    Hello,
    I have a very simple question: I want to put an Iage inside a Rectangle. Something like this:

    @
    Rectangle {
    width: 800
    height: 600
    radius: 20

    Image {
        source: "path/to/file.png"
        anchors.fill: parent
        fillMode: Image.PreserveAspectCrop
    } 
    

    }
    @

    The problem is the image ignores the rectangle's radius! Hence, it extends over the corners.
    How to draw the images really "inside" the rectangle, so the corners are reduced according?

    Thanks!
    Mark

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JapieKrekel
      wrote on last edited by
      #2

      See "QTBUG-9008":https://bugreports.qt-project.org/browse/QTBUG-9008

      It is as designed.

      It is not handy, but what I do is make an image for the rounded rectangle with the corners having the color of the background, and use it in a border-image so I can stretch it without distorting it. I make that lay on top of my content of the rounded rect .
      @
      Item {
      width: 800
      height: 600
      Image {
      source: "path/to/file.png"
      anchors.fill: parent
      fillMode: Image.PreserveAspectCrop
      }

      // last so it is on top (or use the z: )
      BorderImage {
          source: "roundedrect.png"
          anchors.fill: parent
          border {left: 25; top: 25; right: 25; bottom: 25}
      }
      

      }
      @

      1 Reply Last reply
      0
      • _ Offline
        _ Offline
        _Mark_
        wrote on last edited by
        #3

        What a pity! QML is so powerful I'm astonished it cannot mask an image. I know the docs says for "performance" reasons, but let the choice to the user!

        Anyway I can't use your solution, unfortunately. I need to generate on-the-fly (at runtime) the mask. The application searches for any image in a folder and put each one in a rounded rectangle with different sizes and colors.

        I found this:

        http://qt-project.org/forums/viewthread/7037

        I removed the import Qt.labs.shaders 1.0 and changed ShaderEffectItem in ShaderEffect - still no chance.
        I got the following error:

        @QQuickShaderEffect: 'qt_ModelViewProjectionMatrix' does not have a matching property!
        @

        I searched for any documentation but I found nothing. Do you have any idea about?

        skolS 1 Reply Last reply
        0
        • J Offline
          J Offline
          JapieKrekel
          wrote on last edited by
          #4

          Ah sorry to here that.

          I have no knowledge of GLSL. So hopefully someone else can help you with that.

          1 Reply Last reply
          0
          • _ _Mark_

            What a pity! QML is so powerful I'm astonished it cannot mask an image. I know the docs says for "performance" reasons, but let the choice to the user!

            Anyway I can't use your solution, unfortunately. I need to generate on-the-fly (at runtime) the mask. The application searches for any image in a folder and put each one in a rounded rectangle with different sizes and colors.

            I found this:

            http://qt-project.org/forums/viewthread/7037

            I removed the import Qt.labs.shaders 1.0 and changed ShaderEffectItem in ShaderEffect - still no chance.
            I got the following error:

            @QQuickShaderEffect: 'qt_ModelViewProjectionMatrix' does not have a matching property!
            @

            I searched for any documentation but I found nothing. Do you have any idea about?

            skolS Offline
            skolS Offline
            skol
            wrote on last edited by
            #5

            @_Mark_ qWarning("ShaderEffect: qt_ModelViewProjectionMatrix is deprecated. Use qt_Matrix instead.");

            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