이 페이지에서

QSvgGenerator Class

QSvgGenerator 클래스는 SVG 그림을 생성하는 데 사용되는 페인트 디바이스를 제공합니다. 더 보기...

헤더: #include <QSvgGenerator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Svg)
target_link_libraries(mytarget PRIVATE Qt6::Svg)
qmake: QT += svg
상속: QPaintDevice

참고: 이 클래스의 모든 함수는 재진입 가능합니다.

공개 유형

(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

상세 설명

이 페인트 디바이스는 SVG(Scalable Vector Graphics) 드로잉을 나타냅니다. 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::SvgTiny120생성된 문서는 SVG Tiny 1.2 사양을 따릅니다.
QSvgGenerator::SvgVersion::Svg111생성된 문서는 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 및 viewBox도 참조하십시오 .

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 도형의 뷰박스를 저장합니다.

기본적으로 이 속성은 ` 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)

version 버전의 SVG를 사용하는 새로운 생성기를 생성합니다.

이 함수는 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.