|  | Home · All Classes · Modules

# QSvgGenerator Class Reference
[QtSvg module]

The QSvgGenerator class provides a paint device that is used to create SVG drawings. More...

Inherits QPaintDevice.

### Methods

- __init__ (self)
- QString description (self)
- QString fileName (self)
- int metric (self, QPaintDevice.PaintDeviceMetric)
- QIODevice outputDevice (self)
- QPaintEngine paintEngine (self)
- int resolution (self)
- setDescription (self, QString)
- setFileName (self, QString)
- setOutputDevice (self, QIODevice)
- setResolution (self, int)
- setSize (self, QSize)
- setTitle (self, QString)
- setViewBox (self, QRect)
- setViewBox (self, QRectF)
- QSize size (self)
- QString title (self)
- QRect viewBox (self)
- QRectF viewBoxF (self)

## Detailed Description

The QSvgGenerator class provides a paint device that is used to create SVG drawings.

This paint device represents a Scalable Vector Graphics (SVG) drawing. Like QPrinter, it is designed as a write-only device that generates output in a specific format.

To write an SVG file, you first need to configure the output by setting the fileName or outputDevice properties. It is usually necessary to specify the size of the drawing by setting the size property, and in some cases where the drawing will be included in another, the viewBox property also needs to be set.

         QSvgGenerator generator;
         generator.setFileName(path);
         generator.setSize(QSize(200, 200));
         generator.setViewBox(QRect(0, 0, 200, 200));
         generator.setTitle(tr("SVG Generator Example Drawing"));
         generator.setDescription(tr("An SVG drawing created by the SVG Generator "
                                     "Example provided with Qt."));

Other meta-data can be specified by setting the title, description and resolution properties.

As with other QPaintDevice subclasses, a QPainter object is used to paint onto an instance of this class:

         QPainter painter;
         painter.begin(&generator);
         ...
         painter.end();

Painting is performed in the same way as for any other paint device. However, it is necessary to use the QPainter.begin() and end() to explicitly begin and end painting on the device.

The SVG Generator Example shows how the same painting commands can be used for painting a widget and writing an SVG file.

See also QSvgRenderer, QSvgWidget, and About SVG.

## Method Documentation

### QSvgGenerator.__init__ (self)

Constructs a new generator.

### QString QSvgGenerator.description (self)

### QString QSvgGenerator.fileName (self)

### int QSvgGenerator.metric (self, QPaintDevice.PaintDeviceMetric)

Reimplemented from QPaintDevice.metric().

### QIODevice QSvgGenerator.outputDevice (self)

### QPaintEngine QSvgGenerator.paintEngine (self)

Reimplemented from QPaintDevice.paintEngine().

Returns the paint engine used to render graphics to be converted to SVG format information.

### int QSvgGenerator.resolution (self)

### QSvgGenerator.setDescription (self, QString)

### QSvgGenerator.setFileName (self, QString)

### QSvgGenerator.setOutputDevice (self, QIODevice)

### QSvgGenerator.setResolution (self, int)

### QSvgGenerator.setSize (self, QSize)

### QSvgGenerator.setTitle (self, QString)

### QSvgGenerator.setViewBox (self, QRect)

### QSvgGenerator.setViewBox (self, QRectF)

### QSize QSvgGenerator.size (self)

### QString QSvgGenerator.title (self)

### QRect QSvgGenerator.viewBox (self)

Returns viewBoxF().toRect().

This function was introduced in Qt 4.5.

See also setViewBox() and viewBoxF().

### QRectF QSvgGenerator.viewBoxF (self)