[PyQt] No output from QSvgGenerator

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


Hello,
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.svg.setFileName(fileName)
      self.svg.setSize(self.size())
      self.svg.setResolution(600)
      self.painter = QtGui.QPainter(self.svg)
      self.render(self.painter)

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?
Thanks!

Luke


More information about the PyQt mailing list