QSvgGenerator 類

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

頭: #include <QSvgGenerator>
qmake: QT += svg
Since: Qt 4.3
繼承: QPaintDevice

注意: 此類的所有函數 可重入 .

特性

公共函數

QSvgGenerator ()
virtual ~QSvgGenerator ()
QString description () const
QString fileName () const
QIODevice * outputDevice () const
int resolution () const
void setDescription (const QString & 描述 )
void setFileName (const QString & fileName )
void setOutputDevice (QIODevice * outputDevice )
void setResolution (int dpi )
void setSize (const QSize & size )
void setTitle (const QString & title )
void setViewBox (const QRect & viewBox )
void setViewBox (const QRectF & viewBox )
QSize size () const
QString title () const
QRect viewBox () const
QRectF viewBoxF () const

重實現保護函數

virtual int metric (QPaintDevice::PaintDeviceMetric metric ) const override
virtual QPaintEngine * paintEngine () const override

詳細描述

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

此繪圖設備錶示 SVG (可伸縮嚮量圖形) 繪製。像 QPrinter,它被設計為隻寫設備以按特定格式生成輸齣。

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 , 描述 and resolution 特性。

As with other QPaintDevice 子類, 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 () 和 end() to explicitly begin and end painting on the device.

The SVG 生成器範例 shows how the same painting commands can be used for painting a widget and writing an SVG file.

另請參閱 QSvgRenderer , QSvgWidget ,和 Qt SVG C++ 類 .

特性文檔編製

description : QString

此特性保持生成 SVG 繪製的描述

該特性在 Qt 4.5 引入。

訪問函數:

QString 描述 () const
void setDescription (const QString & 描述 )

另請參閱 title .

fileName : QString

This property holds the target filename for the generated SVG drawing

該特性在 Qt 4.5 引入。

訪問函數:

QString fileName () const
void setFileName (const QString & fileName )

另請參閱 outputDevice .

outputDevice : 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.

該特性在 Qt 4.5 引入。

訪問函數:

QIODevice * outputDevice () const
void setOutputDevice (QIODevice * outputDevice )

另請參閱 fileName .

resolution : 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.

該特性在 Qt 4.5 引入。

訪問函數:

int resolution () const
void setResolution (int dpi )

另請參閱 size and viewBox .

size : 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> 元素。

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

該特性在 Qt 4.5 引入。

訪問函數:

QSize size () const
void setSize (const QSize & size )

另請參閱 viewBox and resolution .

title : QString

This property holds the title of the generated SVG drawing

該特性在 Qt 4.5 引入。

訪問函數:

QString title () const
void setTitle (const QString & title )

另請參閱 description .

viewBox : 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> 元素。

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

該特性在 Qt 4.5 引入。

訪問函數:

QRectF viewBoxF () const
void setViewBox (const QRect & viewBox )
void setViewBox (const QRectF & viewBox )

另請參閱 viewBox (), size ,和 resolution .

成員函數文檔編製

QSvgGenerator:: QSvgGenerator ()

構造新的生成器。

[虛擬] QSvgGenerator:: ~QSvgGenerator ()

銷毀生成器。

[override virtual protected] int QSvgGenerator:: metric ( QPaintDevice::PaintDeviceMetric metric ) const

重實現自 QPaintDevice::metric ().

[override virtual protected] QPaintEngine *QSvgGenerator:: paintEngine () const

重實現自 QPaintDevice::paintEngine ().

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

QRect QSvgGenerator:: viewBox () const

返迴 viewBoxF ().toRect().

該函數在 Qt 4.5 引入。

另請參閱 setViewBox () 和 viewBoxF ().