Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-80260

QSvgRenderer svg fill rgba support missing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P4: Low
    • None
    • 5.13.2
    • SVG Support
    • None
    • Linux/X11

    Description

      I have some SVG files using the fill attribute as for example 

      fill="rgba(255,0,0,0.2)"

      and it renders back. Here for testing

      <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path d="M8 16h8V8H8v8zm12 24h8v-8h-8v8zM8 40h8v-8H8v8zm0-12h8v-8H8v8zm12 0h8v-8h-8v8zM32 8v8h8V8h-8zm-12 8h8V8h-8v8zm12 12h8v-8h-8v8zm0 12h8v-8h-8v8z" fill="rgba(255,0,0,0.2)"/></svg>
      
      

      After some testing I found out that QSvgRenderer supports the  fill-opacity

      <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><path d="M8 16h8V8H8v8zm12 24h8v-8h-8v8zM8 40h8v-8H8v8zm0-12h8v-8H8v8zm12 0h8v-8h-8v8zM32 8v8h8V8h-8zm-12 8h8V8h-8v8zm12 12h8v-8h-8v8zm0 12h8v-8h-8v8z" fill="rgb(255,0,0)" fill-opacity="0.2"/></svg> 

      It would be better to support fill="rgba..." to rather than writing scripts to separated fill and fill-opacity fields on existing files.

      Here's the code I use to render my icons

       

      QFile file(iconPath);
      file.open(QIODevice::ReadOnly);
      baData = file.readAll();
      // load svg contents to xml document and edit contents
      QDomDocument doc;
      doc.setContent(baData);
      file.close();
      // Change the fill color attributes here
      // create svg renderer with edited contents
      const QByteArray docArr = doc.toByteArray();
      QSvgRenderer svgRenderer(docArr);
      // create pixmap target (could be a QImage)
      QPixmap pix(svgRenderer.defaultSize());
      pix.fill(Qt::transparent);
      // create painter to act over pixmap
      QPainter pixPainter(&pix);
      // use renderer to render over painter which paints on pixmap
      svgRenderer.render(&pixPainter);
      QIcon myicon(pix);
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            damienlefevre Damien LEFEVRE
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes