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. OpacityMask reduces Image quality
Qt 6.11 is out! See what's new in the release blog

OpacityMask reduces Image quality

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.6k 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.
  • C Offline
    C Offline
    ccatterina
    wrote on last edited by ccatterina
    #1

    Hi,
    I'm developing a KDE widget in QML (Qt6.8.2), in the widget there is an Image that is downscaled to ~50 pixels square.
    The resulting image has a decent quality, but when I apply an OpacityMask to create rounded borders, the image becomes a little more blurry.

    Here's my code:

        Image {
            id: imageComponent
            visible: type === PanelIcon.Type.Image
            anchors.fill: parent
            sourceSize: Qt.size(root.size * Screen.devicePixelRatio, root.size * Screen.devicePixelRatio)
            source: root.imageUrl
            fillMode: Image.PreserveAspectFit
            
            onStatusChanged: {
                imageStatusTimer.restart()
                if (status === Image.Ready) imageColors.update()
            }
            onVisibleChanged: {
                if (status === Image.Ready) imageColors.update()
            }
    
            layer.enabled: imageRadius > 0
            layer.effect: OpacityMask {
                maskSource: Item {
                    width: imageComponent.width
                    height: imageComponent.height
                    Rectangle {
                        anchors.fill: parent
                        radius: imageRadius
                    }
                }
            }
        }
    

    Screenshots with/without rounded borders (the difference is less visible here, probably due to the quality of the screenshot):
    Screenshot_20250421_111645-1.png
    Screenshot_20250421_111737-1.png

    Could someone help me to understand why it happens and to find a solution?
    Thank you!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Shankarlinga M
      wrote on last edited by Shankarlinga M
      #2

      @ccatterina Try increasing the device pixel ratio scaling factor slightly.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ccatterina
        wrote on last edited by
        #3

        Hi @Shankarlinga-M, I noticed that the display scale option was set to 120%. Setting it back to 100% resolves the issue. Is there a way to make the image appear clear regardless of the display scale? Thank you so much!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Shankarlinga M
          wrote on last edited by
          #4

          @ccatterina Use a hardcoded pixel size for sourceSize rather than relying on relative scaling:
          sourceSize: Qt.size(128, 128)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ccatterina
            wrote on last edited by
            #5

            @Shankarlinga-M sorry for the late reply and thank you.

            Indeed, I found that the issue is related to the fact that the Screen.DevicePixelRatio is rounded up. When I set the display scaling to 120% the value of Screen.DevicePixelRatio is set to 2 instead of 1.2. Replacing Screen.DevicePixelRatio in the code with 1.2 makes the image look fine.

            I found also an other thread about this issue https://forum.qt.io/topic/160425/wayland-and-fractional-screen-scaling-reported-as-integer-by-wayland-info-and-q-screen/3

            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