[PyQt] No output from QSvgGenerator
David Boddie
dboddie at trolltech.com
Tue May 27 18:00:02 BST 2008
On Tue May 27 17:00:23 BST 2008, Luke Campagnola wrote:
> 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.
You need to "close" the painter, either by making "painter" a local
variable or by wrapping render() in calls to the painter's begin()
and end() methods.
Either
[ ... ]
painter = QtGui.QPainter(self.svg)
self.render(self.painter)
or
[ ... ]
self.painter = QtGui.QPainter()
self.painter.begin(self.svg)
self.render(self.painter)
self.painter.end()
Since you probably don't need to make "painter" an instance variable, the
first option is probably the way to go.
David
--
David Boddie
Lead Technical Writer, Trolltech ASA
More information about the PyQt
mailing list