CopperSpice API  1.7.4
QSvgGenerator Class Reference

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

Inheritance diagram for QSvgGenerator:

Public Methods

QSvgGenerator ()

~QSvgGenerator ()

QRect viewBox () const

Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()

int colorCount () const

int depth () const

int devicePixelRatio () const

qreal devicePixelRatioF () const

int height () const

int heightMM () const

int logicalDpiX () const

int logicalDpiY () const

bool paintingActive () const

int physicalDpiX () const

int physicalDpiY () const

int width () const

int widthMM () const

Protected Methods

int metric (QPaintDevice::PaintDeviceMetric metric) const override

QPaintEnginepaintEngine () const override

Protected Methods inherited from QPaintDevice
QPaintDevice ()

Properties

description

fileName

outputDevice

resolution

size

title

viewBox

Public Types inherited from QPaintDevice
enum  PaintDeviceMetric

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."));

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);
// do something
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.

QSvgRenderer, QSvgWidget, About SVG

Constructor & Destructor Documentation

 QSvgGenerator::QSvgGenerator ( )

Constructs a new generator.

 QSvgGenerator::~QSvgGenerator ( )

Destroys the generator.

Method Documentation

 int QSvgGenerator::metric ( QPaintDevice::PaintDeviceMetric metric ) const
overrideprotectedvirtual

Reimplemented from QPaintDevice::metric()

 QPaintEngine * QSvgGenerator::paintEngine ( ) const
overrideprotectedvirtual

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

Implements QPaintDevice::paintEngine()

 QRect QSvgGenerator::viewBox ( ) const

Returns viewBoxF().toRect().

setViewBox(), viewBoxF()

Property Documentation

 QSvgGenerator::description

This property holds the description of the generated SVG drawing.

title
PropertiesClass Methods
write setDescription
 QSvgGenerator::fileName

This property holds the target filename for the generated SVG drawing.

outputDevice
PropertiesClass Methods
write setFileName
 QSvgGenerator::outputDevice

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.

fileName
PropertiesClass Methods
write setOutputDevice
 QSvgGenerator::resolution

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.

size, viewBox
PropertiesClass Methods
write setResolution
 QSvgGenerator::size

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.
viewBox, resolution
PropertiesClass Methods
write setSize
 QSvgGenerator::title

This property holds the title of the generated SVG drawing.

description
PropertiesClass Methods
write setTitle
 QSvgGenerator::viewBox

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.