Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Saving QGraphicsScene (vector graphics PLUS IMAGE) to SVG

Saving QGraphicsScene (vector graphics PLUS IMAGE) to SVG

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.2k 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.
  • B Offline
    B Offline
    bliako
    wrote on last edited by
    #1

    Hello,

    I am creating a QGraphicsScene and adding several points (as tiny QGraphicsRectItem). I am also creating a path as QGraphicsPathItem. I am able to export this to SVG using the well documented method:

    QSvgGenerator generator;
    generator.setResolution((int )dpi);
    generator.setFileName(afilename);
    
    QPainter painter;
    painter.begin(&generator);
    painter.setRenderHint(QPainter::Antialiasing);
    // myGraphicsScene is a subclass of QGraphicsScene
    myGraphicsScene->render(&painter);
    painter.end();
    

    And that works fine. Output SVG is fine.

    Then I am reading an image from file and convert it to a QBrush which I use to fillPath(), that is to flood-fill my path with this image/brush.

    I can see the vector graphics and the filled-with-image path on my canvas just fine. I can also see same results when outputting as an image (PNG/JPG) using similar method as above.

    BUT, I can not see the image in my SVG output file. Everything else is OK, path, rects. Just fine. But there is no image. And as far as I could understand by reading the output SVG text file, there is no mention of any image in that file.

    Does anyone have any hints for solving this problem?

    Thanks,
    bliako

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This might be outside of the static features of SVG tiny 1.2 specification implemented by the QtSvg module.

      See here

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bliako
        wrote on last edited by bliako
        #3

        Thanks for your reply. I found this link via the link you provided: [https://www.w3.org/Graphics/SVG/feature/1.2/#SVG-static](link url) Which lists all the static features of SVG 1.2 as:

        Feature String:
            http://www.w3.org/Graphics/SVG/feature/1.2/#SVG-static
        User Agent Supports:
            All of the following features (described below)
        ...
        feature/1.2/#ConditionalProcessingAttribute"
                "http://www.w3.org/Graphics/SVG/feature/1.2/#Image"
        ... etc.
        
         For SVG viewers,
        "http://www.w3.org/Graphics/SVG/feature/1.2/#SVG-static"
        indicates that the viewer can process and render
        successfully all of the language features in the
        modules corresponding to the features
        listed above. 
        

        So, Image support is there as I understand it.

        And I can confirm that if I do

        QPixmap *myPixmap = new QPixmap();
        myPixmap.load(imgfilename);
        ...
        Qpainter painter;
        painter->drawPixmap(0, 0, *myPixmap);
        ...
        

        Then exported SVG file contains an <image element and I can view the image in gimp.

        However, if I add:

        ...
        QBrush *myBrush = new QBrush(*myPixmap);
        ...
        painter->fillPath(myGIPath->path(), *myBrush);
        

        I can see the pixmap on my application's QGraphicsScene fine, but when I export to SVG, image is now missing.

        Am I doing this last bit right?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Except that you don't need to allocate the brush on the heap. The line is fine.

          Did you already check the bug report system ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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