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. Optimized way to colorize SVGs
Forum Updated to NodeBB v4.3 + New Features

Optimized way to colorize SVGs

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

    Hello,
    In terms of performance, what is the best way to colorize total black SVGs inside with QML?
    Based on this topic one way is to use MultiEffect.
    I have two ways to reach my goal.

    1. Load svg file with VectorImage and adding MultiEffect as said in linked topic:
    VectorImage{
        fillMode: VectorImage.PreserveAspectFit
        preferredRendererType: VectorImage.CurveRenderer
        source: "qrc:/svg/icon"
        layer.enabled: true
        layer.effect: MultiEffect {
            brightness: 1.0
            colorization: 1.0
            colorizationColor: "red"
        }
    }
    
    1. Run svgtoqml tool, create a fillColor property to use in ShapePath.fillColor, use in code:
      Generated code:
    Item {
        implicitWidth: 24
        implicitHeight: 24
        property color fillColor: "white"
        component AnimationsInfo : QtObject
        {
            property bool paused: false
            property int loops: 1
            signal restart()
        }
        property AnimationsInfo animations : AnimationsInfo {}
        transform: [
            Translate { x: 0; y: 960 },
            Scale { xScale: width / 960; yScale: height / 960 }
        ]
        id: __qt_toplevel
        Shape {
            preferredRendererType: Shape.CurveRenderer
            id: _qt_node0
            ShapePath {
                id: _qt_shapePath_0
                strokeColor: "transparent"
                fillColor: __qt_toplevel.fillColor
                fillRule: ShapePath.WindingFill
                pathHints: ShapePath.PathQuadratic | ShapePath.PathNonIntersecting | ShapePath.PathNonOverlappingControlPointTriangles
                PathSvg { path: "..." }
            }
        }
    }
    

    Used with:

    Icon {
        fillColor: "red" 
    }
    

    The result is the same. However, which one is better when considering that all the SVG icons are provided at build time and the Qt Quick Compiler flag is set to true in the Qt VS Tools?

    JKSHJ 1 Reply Last reply
    1
    • T TheEnigmist

      Hello,
      In terms of performance, what is the best way to colorize total black SVGs inside with QML?
      Based on this topic one way is to use MultiEffect.
      I have two ways to reach my goal.

      1. Load svg file with VectorImage and adding MultiEffect as said in linked topic:
      VectorImage{
          fillMode: VectorImage.PreserveAspectFit
          preferredRendererType: VectorImage.CurveRenderer
          source: "qrc:/svg/icon"
          layer.enabled: true
          layer.effect: MultiEffect {
              brightness: 1.0
              colorization: 1.0
              colorizationColor: "red"
          }
      }
      
      1. Run svgtoqml tool, create a fillColor property to use in ShapePath.fillColor, use in code:
        Generated code:
      Item {
          implicitWidth: 24
          implicitHeight: 24
          property color fillColor: "white"
          component AnimationsInfo : QtObject
          {
              property bool paused: false
              property int loops: 1
              signal restart()
          }
          property AnimationsInfo animations : AnimationsInfo {}
          transform: [
              Translate { x: 0; y: 960 },
              Scale { xScale: width / 960; yScale: height / 960 }
          ]
          id: __qt_toplevel
          Shape {
              preferredRendererType: Shape.CurveRenderer
              id: _qt_node0
              ShapePath {
                  id: _qt_shapePath_0
                  strokeColor: "transparent"
                  fillColor: __qt_toplevel.fillColor
                  fillRule: ShapePath.WindingFill
                  pathHints: ShapePath.PathQuadratic | ShapePath.PathNonIntersecting | ShapePath.PathNonOverlappingControlPointTriangles
                  PathSvg { path: "..." }
              }
          }
      }
      

      Used with:

      Icon {
          fillColor: "red" 
      }
      

      The result is the same. However, which one is better when considering that all the SVG icons are provided at build time and the Qt Quick Compiler flag is set to true in the Qt VS Tools?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote last edited by
      #2

      @TheEnigmist said in Optimized way to colorize SVGs:

      which one is better

      Which metric(s) are most important to you?

      • Initialization time?
      • CPU load?
      • Memory consumption?
      • Something else?

      Benchmark and compare.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      T 1 Reply Last reply
      0
      • JKSHJ JKSH

        @TheEnigmist said in Optimized way to colorize SVGs:

        which one is better

        Which metric(s) are most important to you?

        • Initialization time?
        • CPU load?
        • Memory consumption?
        • Something else?

        Benchmark and compare.

        T Offline
        T Offline
        TheEnigmist
        wrote last edited by
        #3

        @JKSH
        I think GPU load since MultiEffect uses GPU. I need to run debug bench in VS to check all loads

        1 Reply Last reply
        0
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote last edited by
          #4

          As an alternative, we are using Icons to color svg images meant for button or action icons : https://doc.qt.io/qt-6/qtquickcontrols-icons.html#icon-themes

          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