QSvgGenerator 類

QSvgGenerator 類提供用於創建 SVG 繪製的描繪設備。 更多...

頭: #include <QSvgGenerator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Svg)
target_link_libraries(mytarget PRIVATE Qt6::Svg)
qmake: QT += svg
繼承: QPaintDevice

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

公共類型

(從 6.5 起) 枚舉類 SvgVersion { SvgTiny12, Svg11 }

特性

公共函數

QSvgGenerator ()
(從 6.5 起) QSvgGenerator (QSvgGenerator::SvgVersion version )
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
(從 6.5 起) QSvgGenerator::SvgVersion svgVersion () const
QString title () const
QRect viewBox () const
QRectF viewBoxF () const

重實現保護函數

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

詳細描述

此繪圖設備錶示 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 , description 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.

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

成員類型文檔編製

[since 6.5] enum class QSvgGenerator:: SvgVersion

This enumeration describes the version of the SVG output of the generator.

常量 描述
QSvgGenerator::SvgVersion::SvgTiny12 0 The generated document follows the SVG Tiny 1.2 specification.
QSvgGenerator::SvgVersion::Svg11 1 The generated document follows the SVG 1.1 specification.

該枚舉在 Qt 6.5 引入。

特性文檔編製

description : QString

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

訪問函數:

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

另請參閱 title .

fileName : QString

This property holds the target filename for the generated SVG drawing

訪問函數:

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.

訪問函數:

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.

訪問函數:

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.

訪問函數:

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

另請參閱 viewBox and resolution .

title : QString

This property holds the title of the generated SVG drawing

訪問函數:

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.

訪問函數:

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

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

成員函數文檔編製

QSvgGenerator:: QSvgGenerator ()

Constructs a new generator using the SVG Tiny 1.2 profile.

[explicit, since 6.5] QSvgGenerator:: QSvgGenerator ( QSvgGenerator::SvgVersion version )

Constructs a new generator that uses the SVG version version .

該函數在 Qt 6.5 引入。

[virtual noexcept] QSvgGenerator:: ~QSvgGenerator ()

銷毀生成器。

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

重實現: QPaintDevice::metric (QPaintDevice::PaintDeviceMetric metric) const.

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

重實現: QPaintDevice::paintEngine () const.

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

[since 6.5] QSvgGenerator::SvgVersion QSvgGenerator:: svgVersion () const

Returns the version of the SVG document that this generator is producing.

該函數在 Qt 6.5 引入。

QRect QSvgGenerator:: viewBox () const

返迴 viewBoxF ().toRect().

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