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

QGraphicsSvgItem is rasterized by default with QSvgGenerator

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 4.7.3, 5.5.1
    • GUI: Painting, SVG Support
    • None

    Description

      As per bug https://bugreports.qt.io/browse/QTBUG-19563

      The following code will cause the QGraphicsSvgItem to be rendered as binary.

      #include <QApplication>
      
      #include <QGraphicsScene>
      #include <QSvgGenerator>
      #include <QGraphicsSvgItem>
      #include <QGraphicsScene>
      #include <QBuffer>
      #include <QDebug>
      #include <QPainter>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          QBuffer b;
          QSvgGenerator p;
          p.setOutputDevice(&b);
          QPainter painter;
          painter.begin(&p);
      
          QGraphicsScene scene;
          auto item = new QGraphicsSvgItem("test.svg");
          scene.addItem(new QGraphicsSvgItem(item);
          scene.render(&painter);
          painter.end();
          qDebug() << QString(b.buffer());
          return 0;
      }
      

      For instance for the image given in attachment the resulting (bogus) svg output is :

      <image x=\"-2\" y=\"-2\" width=\"3\" height=\"3\" preserveAspectRatio=\"none\" xlink:href=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAHklEQVQImV3BsQ0AAAQAsMbmP/8v/sCuBdsSAozyHVpTA0DEkSTtAAAAAElFTkSuQmCC\" />
      

      The output is correct if we add :

          item->setCacheMode(QGraphicsItem::NoCache);
      

      prior to rendering

      Attachments

        1. test.svg
          0.7 kB
          Jean-Michaël Celerier
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sletta Gunnar Sletta
            jcelerier Jean-Michaël Celerier
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes