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. Qt6 color SVG using MultiEffect
Forum Updated to NodeBB v4.3 + New Features

Qt6 color SVG using MultiEffect

Scheduled Pinned Locked Moved Solved QML and Qt Quick
14 Posts 10 Posters 3.6k 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.
  • C Offline
    C Offline
    christofer
    wrote on last edited by christofer
    #5

    Thanks for the replies @mzimmers !

    You inspired me to experiment more. It turns out all I have to do is change the existing SVG fill from black to white.

    I changed...

    <g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)"
    fill="#000000" stroke="none">
    

    to...

    <g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)"
    fill="white" stroke="none">
    

    Result...
    Screen Shot 2023-04-04 at 6.00.26 AM.png

    The changes are in the GitLab project, tag qt-forum-post-02

    mzimmersM 1 Reply Last reply
    0
    • C christofer has marked this topic as solved on
    • C christofer

      Thanks for the replies @mzimmers !

      You inspired me to experiment more. It turns out all I have to do is change the existing SVG fill from black to white.

      I changed...

      <g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)"
      fill="#000000" stroke="none">
      

      to...

      <g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)"
      fill="white" stroke="none">
      

      Result...
      Screen Shot 2023-04-04 at 6.00.26 AM.png

      The changes are in the GitLab project, tag qt-forum-post-02

      mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by mzimmers
      #6

      @christofer interesting. I did some experimentation of my own on the puppy file, and it appears that the problem wasn't the use of the RGB format for specifying the color, but rather the fill of black, or indeed any color other than white (or #ffffff).

      EDIT: scratch the comment below -- I forgot my own advice of hiding the original image.

      As a side note, I also noticed that when using the Image inside a Layout, you can't use the anchors property, so the MultiEffect appear below (in the case of a ColumnLayout) the original image. My workaround was to put the Image and the MultiEffect in an Item, so I could use anchors, but there might be a more elegant way to accomplish this.

      ekkescornerE 1 Reply Last reply
      0
      • mzimmersM mzimmers referenced this topic on
      • mzimmersM mzimmers

        @christofer interesting. I did some experimentation of my own on the puppy file, and it appears that the problem wasn't the use of the RGB format for specifying the color, but rather the fill of black, or indeed any color other than white (or #ffffff).

        EDIT: scratch the comment below -- I forgot my own advice of hiding the original image.

        As a side note, I also noticed that when using the Image inside a Layout, you can't use the anchors property, so the MultiEffect appear below (in the case of a ColumnLayout) the original image. My workaround was to put the Image and the MultiEffect in an Item, so I could use anchors, but there might be a more elegant way to accomplish this.

        ekkescornerE Offline
        ekkescornerE Offline
        ekkescorner
        Qt Champions 2016
        wrote on last edited by ekkescorner
        #7

        @mzimmers tried to colorize a png
        my old code:

        Image {
            id: image
            ....
            ColorOverlay {
                id: colorOverlay
                anchors.fill: image
                source: image
                color: primaryColor
            }
        

        new code:

        Image {
                id: image
                ....    
        MultiEffect {
                id: colorOverlay
                    source: image
                    anchors.fill: image
                    colorization: 1.0
                    colorizationColor: primaryColor
                }
        

        But the Image isn't colorized.
        -----------edit: foundSolution

        1. separated Image and MultiEffect and placed both inside an Item
        2. then set visible false at Image
          result: not colorized, but found the reason
          the png was a black icon - changed this and used a white icon and now colorizing works.
          So this is different to QtQuickEffects and Qt 5.15

        ekke ... Qt Champion 2016 | 2024 ... mobile business apps
        5.15 --> 6.8 https://t1p.de/ekkeChecklist
        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alvarosaes
          wrote on last edited by alvarosaes
          #8

          Hello, I also had this question so i asked directly via Qt support. I got this response:

          > Thank you for you response. So, ColorOverlayEffect from import
          > QtQuick.Studio.Effects 1.0 is not equivalent to this? I didnt have this
          > problem while using that effect
          
          Yeah, different effect:
          
          fragColor = vec4(mix(pixelColor.rgb/max(pixelColor.a, 0.00390625), color.rgb/max(color.a, 0.00390625), color.a) * pixelColor.a, pixelColor.a) * qt_Opacity;
          
          Compared to this for colorization:
          
          color.rgb = (color.rgb - 0.5 * color.a) * (1.0 + contrast) + 0.5 * color.a;
          color.rgb += brightness * color.a;
          float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
          float colorizationAlpha = colorization * colorizationColor.a;
          color.rgb = mix(color.rgb, gray * colorizationColor.rgb, colorizationAlpha);
          color.rgb = mix(vec3(gray), color.rgb, 1.0 + saturation);
          

          So i only see 2 solutions:

          • Convert all your svgs to fill white
          • Rollback to use ColorOverlayEffect

          @mzimmers @christofer @ekkescorner

          1 Reply Last reply
          1
          • S Offline
            S Offline
            srce
            wrote on last edited by srce
            #9

            Rather than converting pngs from black to white, setting brightness to 1 (in addition to colorize) should have a similar effect.

            M 1 Reply Last reply
            4
            • Q Offline
              Q Offline
              QKelteseth
              wrote on last edited by
              #10

              @srce thank you!!

              1 Reply Last reply
              0
              • S srce

                Rather than converting pngs from black to white, setting brightness to 1 (in addition to colorize) should have a similar effect.

                M Offline
                M Offline
                MattP2
                wrote on last edited by MattP2
                #11

                @srce said in Qt6 color SVG using MultiEffect:

                Rather than converting pngs from black to white, setting brightness to 1 (in addition to colorize) should have a similar effect.

                This is the answer, a big thank you.

                So, visible: false, parent Item and color in svg are not required.
                This is working with any svg:

                Image {
                    // image properties
                    layer.enabled: true
                    layer.effect: MultiEffect {
                        brightness: 1.0
                        colorization: 1.0
                        colorizationColor: enabled ? Material.primaryTextColor : Material.secondaryTextColor
                    }
                }
                
                P A N 3 Replies Last reply
                1
                • nicwainwrightN nicwainwright referenced this topic on
                • M MattP2

                  @srce said in Qt6 color SVG using MultiEffect:

                  Rather than converting pngs from black to white, setting brightness to 1 (in addition to colorize) should have a similar effect.

                  This is the answer, a big thank you.

                  So, visible: false, parent Item and color in svg are not required.
                  This is working with any svg:

                  Image {
                      // image properties
                      layer.enabled: true
                      layer.effect: MultiEffect {
                          brightness: 1.0
                          colorization: 1.0
                          colorizationColor: enabled ? Material.primaryTextColor : Material.secondaryTextColor
                      }
                  }
                  
                  P Offline
                  P Offline
                  PeterG76
                  wrote on last edited by
                  #12

                  @MattP2 Thanks.

                  Setting "brightness: 1.0" worked for me too. I can now successfully colorize a black PGN Image using MultiEffect.

                  1 Reply Last reply
                  0
                  • M MattP2

                    @srce said in Qt6 color SVG using MultiEffect:

                    Rather than converting pngs from black to white, setting brightness to 1 (in addition to colorize) should have a similar effect.

                    This is the answer, a big thank you.

                    So, visible: false, parent Item and color in svg are not required.
                    This is working with any svg:

                    Image {
                        // image properties
                        layer.enabled: true
                        layer.effect: MultiEffect {
                            brightness: 1.0
                            colorization: 1.0
                            colorizationColor: enabled ? Material.primaryTextColor : Material.secondaryTextColor
                        }
                    }
                    
                    A Offline
                    A Offline
                    Aleksey Asensus
                    wrote on last edited by Aleksey Asensus
                    #13

                    @srce said in Qt6 color SVG using MultiEffect:

                    Rather than converting pngs from black to white, setting brightness to 1 (in addition to colorize) should have a similar effect.

                    Yep, this works for me, thanks, however Qt 5 solution more flexible: with ColorOverlay I can set color: "transparent" to fully keep original icon where necessary, here icon becomes white for some reason, even if MultiEffect item or layer is not visible/enabled. So still forced to stay on ColorOverlay.

                    1 Reply Last reply
                    0
                    • M MattP2

                      @srce said in Qt6 color SVG using MultiEffect:

                      Rather than converting pngs from black to white, setting brightness to 1 (in addition to colorize) should have a similar effect.

                      This is the answer, a big thank you.

                      So, visible: false, parent Item and color in svg are not required.
                      This is working with any svg:

                      Image {
                          // image properties
                          layer.enabled: true
                          layer.effect: MultiEffect {
                              brightness: 1.0
                              colorization: 1.0
                              colorizationColor: enabled ? Material.primaryTextColor : Material.secondaryTextColor
                          }
                      }
                      
                      N Offline
                      N Offline
                      nilsl
                      wrote last edited by
                      #14

                      @MattP2 I don't see how this works. Depending on your input/original color you will get a different gray value in the computation:

                      color.rgb += brightness * color.a;
                      float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
                      

                      Then this gray value will affect to colorizationColor in:

                      color.rgb = mix(color.rgb, gray * colorizationColor.rgb, colorizationAlpha);
                      

                      So even if colorizationAlpha is 1.0, the gray affects the output.

                      It would work, if color was clamped to (1,1,1) after applyiing the brightness, but that doesn't seem to happen. I always get my colorizationColor scaled in the result, even with brightness: 1.

                      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