QSvgGenerator Class Reference

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

  1. #include <QSvgGenerator>

Inherits: QPaintDevice.

Note: All functions in this class are reentrant.

This class was introduced in Qt 4.3.

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.

  1.     QSvgGenerator generator;
  2.     generator.setFileName(path);
  3.     generator.setSize(QSize(200, 200));
  4.     generator.setViewBox(QRect(0, 0, 200, 200));
  5.     generator.setTitle(tr("SVG Generator Example Drawing"));
  6.     generator.setDescription(tr("An SVG drawing created by the SVG Generator "
  7.                                 "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:

  1.     QPainter painter;
  2.     painter.begin(&generator);
  3.     ...
  4.     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.

Properties

Toggle detailsdescriptiondescription : QString

This property holds the description of the generated SVG drawing

See also title.

Access functions:

Look up this member in the source code.

Toggle detailsfileNamefileName : QString

This property holds the target filename for the generated SVG drawing

See also outputDevice.

Access functions:

Look up this member in the source code.

Toggle detailsoutputDeviceoutputDevice : QIODevice *

This property holds the output device for the generated SVG drawing

If both output device and file name are specified, the output device will have precedence.

See also fileName.

Access functions:

Look up this member in the source code.

Toggle detailsresolutionresolution : int

This property holds the resolution of the generated output

The resolution is specified in dots per inch, and is used to calculate the physical size of an SVG drawing.

See also size and viewBox.

Access functions:

Look up this member in the source code.

Toggle detailssizesize : QSize

This property holds the size of the generated SVG drawing

By default this property is set to QSize(-1, -1), which indicates that the generator should not output the width and height attributes of the <svg> element.

Note: It is not possible to change this property while a QPainter is active on the generator.

See also viewBox and resolution.

Access functions:

  • void setSize ( const QSize & size )

Look up this member in the source code.

Toggle detailstitletitle : QString

This property holds the title of the generated SVG drawing

See also description.

Access functions:

Look up this member in the source code.

Toggle detailsviewBoxviewBox : QRectF

This property holds the viewBox of the generated SVG drawing

By default this property is set to QRect(0, 0, -1, -1), which indicates that the generator should not output the viewBox attribute of the <svg> element.

Note: It is not possible to change this property while a QPainter is active on the generator.

See also viewBox(), size, and resolution.

Access functions:

Look up this member in the source code.

    Public Functions

    Toggle details QSvgGenerator

    QSvgGeneratorQSvgGenerator () ()

    Constructs a new generator.

    Look up this member in the source code.

    Toggle details QSvgGenerator

    ~QSvgGenerator~QSvgGenerator () ()

    Destroys the generator.

    Look up this member in the source code.

    Toggle details int QSvgGenerator

    metricmetric ( QPaintDevice::PaintDeviceMetric metric ( QPaintDevice::PaintDeviceMetric metric )const [virtual protected]

    Reimplemented from QPaintDevice::metric().

    Look up this member in the source code.

    Toggle details QPaintEngine * QSvgGenerator

    paintEnginepaintEngine () ()const [virtual protected]

    Reimplemented from QPaintDevice::paintEngine().

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

    Look up this member in the source code.

    Toggle details QRect QSvgGenerator

    viewBoxviewBox () ()const

    Returns viewBoxF().toRect().

    See also setViewBox() and viewBoxF().

    Look up this member in the source code.

      Notes provided by the Qt Community
      Informative
      • 0

      Votes: 0

      Coverage: Qt library 4.7

      Picture of David Villalobos David Villalobos

      Ant Farmer
      19 notes

      Add: QT += svg

      Add this line to your .pro file:

      QT += svg

      [Revisions]