[PyQt] No output from QSvgGenerator

Luke Campagnola lcampagn at email.unc.edu
Tue May 27 17:00:23 BST 2008

I'm trying to generate an SVG file using QGraphicsView and
QSvgGenerator, but the SVG files generated all have 0 size.
Here's a snip of code--a method of my QGraphicsView subclass:

class GraphicsView(QtGui.QGraphicsView):

  [ ... ]

  def writeSvg(self, fileName):
      self.svg = QtSvg.QSvgGenerator()
      self.painter = QtGui.QPainter(self.svg)

When I run writeSvg(), an empty file is created. If I try to run the
function again, it complains that paint devices can not be deleted
while being painted on. I interpret this to mean that when the
function is run the second time, it will try to delete the old
self.svg when creating the new one, and for some reason it believes
the old self.svg is still being painted on.

I have implemented a similar function that generates PNGs by rendering
to a QImage, and this works perfectly.

Anyone have any ideas for me?


More information about the PyQt mailing list