QSvgGenerator 类提供用于创建 SVG 绘制的描绘设备。 更多...
头: | #include <QSvgGenerator> |
CMake: |
find_package(Qt6 COMPONENTS Svg REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Svg) |
qmake: | QT += svg |
继承: | QPaintDevice |
注意: 此类的所有函数 可重入 .
|
QSvgGenerator () | |
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 |
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.
SVG 生成器范例 shows how the same painting commands can be used for painting a widget and writing an SVG file.
另请参阅 QSvgRenderer , QSvgWidget ,和 Qt SVG C++ 类 .
此特性保持生成 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 .
构造新的生成器。
[虚拟]
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.
返回 viewBoxF ().toRect().
另请参阅 setViewBox () 和 viewBoxF ().