QSvgGenerator 类提供用于创建 SVG 绘制的描绘设备。 更多...
头: | #include <QSvgGenerator> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Svg)
target_link_libraries(mytarget PRIVATE Qt6::Svg) |
qmake: | QT += svg |
继承: | QPaintDevice |
注意: 此类的所有函数 可重入 .
(从 6.5 起)
enum class
|
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 & description ) |
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 引入。
此特性保持生成 SVG 绘制的描述
访问函数:
QString | description () const |
void | setDescription (const QString & description ) |
另请参阅 title .
This property holds the target filename for the generated SVG drawing
访问函数:
QString | fileName () const |
void | setFileName (const QString & fileName ) |
另请参阅 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.
访问函数:
QIODevice * | outputDevice () const |
void | setOutputDevice (QIODevice * outputDevice ) |
另请参阅 fileName .
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 ) |
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 .
This property holds the title of the generated SVG drawing
访问函数:
QString | title () const |
void | setTitle (const QString & title ) |
另请参阅 description .
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 .
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 引入。
返回 viewBoxF ().toRect().
另请参阅 setViewBox () 和 viewBoxF ().