QSvgGenerator Class
QSvgGenerator クラスは、SVG 図形を作成するために使用される描画デバイスを提供します。詳細...
| ヘッダー: | #include <QSvgGenerator> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Svg) target_link_libraries(mytarget PRIVATE Qt6::Svg) |
| qmake: | QT += svg |
| 継承元: | QPaintDevice |
- 継承されたメンバーを含むすべてのメンバーの一覧
- QSvgGeneratorは、Paintingクラス群の一部です。
注:このクラスのすべての関数は再入可能です。
パブリック型
(since 6.5) enum class | SvgVersion { SvgTiny12, Svg11 } |
プロパティ
|
パブリック関数
| QSvgGenerator() | |
(since 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 |
(since 6.5) QSvgGenerator::SvgVersion | svgVersion() const |
| QString | title() const |
| QRect | viewBox() const |
| QRectF | viewBoxF() const |
再実装された保護関数
(since 6.11) virtual void | initPainter(QPainter *painter) const override |
| virtual int | metric(QPaintDevice::PaintDeviceMetric metric) const override |
| virtual QPaintEngine * | paintEngine() const override |
詳細な説明
このペイントデバイスは、Scalable Vector Graphics (SVG) 描画を表します。QPrinterと同様に、特定の形式で出力を生成する書き込み専用デバイスとして設計されています。
SVG ファイルを書き込むには、まずfileName またはoutputDevice プロパティを設定して出力を構成する必要があります。通常、size プロパティを設定して図形のサイズを指定する必要がありますが、図形が別の図形に含まれる場合などには、viewBox プロパティも設定する必要があります。
QSvgGenerator generator;
generator.setFileName(path);
generator.setSize(QSize(200, 200));
generator.setViewBox(QRect(0, 0, 200, 200));
generator.setTitle(tr("SVG Generator Drawing"));
generator.setDescription(tr("An SVG drawing created by the SVG Generator"));その他のメタデータは、title 、description 、およびresolution プロパティを設定することで指定できます。
他の `QPaintDevice ` サブクラスと同様に、このクラスのインスタンスへの描画には `QPainter ` オブジェクトが使用されます:
QPainter painter;
painter.begin(&generator);
...
painter.end();描画は、他のペイントデバイスと同様の方法で行われます。ただし、デバイス上での描画を明示的に開始および終了させるには、QPainter::begin() およびend() を使用する必要があります。
QSvgRenderer 、QSvgWidget 、および Qt SVG C++ Classesを参照してください。
メンバ型のドキュメント
[since 6.5] enum class QSvgGenerator::SvgVersion
この列挙は、ジェネレータによるSVG出力のバージョンを表します。
| 定数 | 値 | 説明 |
|---|---|---|
QSvgGenerator::SvgVersion::SvgTiny12 | 0 | 生成されたドキュメントは、SVG Tiny 1.2 仕様に準拠しています。 |
QSvgGenerator::SvgVersion::Svg11 | 1 | 生成されたドキュメントは、SVG 1.1 仕様に準拠しています。 |
この列挙型は Qt 6.5 で導入されました。
プロパティのドキュメント
description : QString
このプロパティには、生成されたSVG図形の説明が格納されます
アクセス関数:
| QString | description() const |
| void | setDescription(const QString &description) |
関連項目: title 。
fileName : QString
このプロパティには、生成されるSVG図形のターゲットファイル名が格納されます
アクセス関数:
| QString | fileName() const |
| void | setFileName(const QString &fileName) |
関連項目: outputDevice 。
outputDevice : QIODevice*
このプロパティには、生成されたSVG図形の出力先が格納されます
出力デバイスとファイル名の両方が指定されている場合、出力デバイスが優先されます。
アクセス関数:
| QIODevice * | outputDevice() const |
| void | setOutputDevice(QIODevice *outputDevice) |
fileNameも参照してください 。
resolution : int
このプロパティは、生成された出力の解像度を保持します
解像度はドット毎インチ(dpi)で指定され、SVG描画の物理的なサイズを計算するために使用されます。
アクセス関数:
| int | resolution() const |
| void | setResolution(int dpi) |
size : QSize
このプロパティは、生成されたSVG図形のサイズを保持します
デフォルトでは、このプロパティは `QSize(-1, -1)` に設定されており、これはジェネレータが `<svg> ` 要素の `width` および `height` 属性を出力しないことを示します。
注: ジェネレータでQPainter が有効になっている間は、このプロパティを変更することはできません 。
アクセス関数:
| QSize | size() const |
| void | setSize(const QSize &size) |
関連項目: viewBox およびresolution 。
title : QString
このプロパティは、生成されたSVG図形のタイトルを保持します
アクセス関数:
| QString | title() const |
| void | setTitle(const QString &title) |
descriptionも参照してください 。
viewBox : QRectF
このプロパティには、生成されたSVG図形のviewBoxが格納されます
デフォルトでは、このプロパティは `QRect(0, 0, -1, -1)` に設定されており、これはジェネレータが `<svg> ` 要素の `viewBox` 属性を出力しないことを示します。
注: ジェネレータで「QPainter 」が有効になっている間は、このプロパティを変更することはできません 。
アクセス関数:
| QRectF | viewBoxF() const |
| void | setViewBox(const QRect &viewBox) |
| void | setViewBox(const QRectF &viewBox) |
関連項目: viewBox()、size 、およびresolution 。
メンバ関数のドキュメント
QSvgGenerator::QSvgGenerator()
SVG Tiny 1.2 プロファイルを使用して、新しいジェネレータを作成します。
[explicit, since 6.5] QSvgGenerator::QSvgGenerator(QSvgGenerator::SvgVersion version)
SVGバージョンversion を使用する新しいジェネレータを作成します。
この関数は Qt 6.5 で導入されました。
[virtual noexcept] QSvgGenerator::~QSvgGenerator()
発電機を破壊する。
[override virtual protected, since 6.11] void QSvgGenerator::initPainter(QPainter *painter) const
この関数は Qt 6.11 で導入されました。
[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 を再実装します。
SVG 形式に変換されるグラフィックをレンダリングするために使用されるペイントエンジンを返します。
[since 6.5] QSvgGenerator::SvgVersion QSvgGenerator::svgVersion() const
このジェネレータが生成しているSVGドキュメントのバージョンを返します。
この関数は Qt 6.5 で導入されました。
QRect QSvgGenerator::viewBox() const
viewBoxF().toRect() を返します。
setViewBox() およびviewBoxF()も参照してください 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.