QSvgGenerator Class

QSvgGenerator 클래스는 SVG 도면을 만드는 데 사용되는 페인트 장치를 제공합니다. 더 보기...

Header: #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

재구현된 보호 기능

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

상세 설명

이 페인트 장치는 스케일러블 벡터 그래픽(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 Example Drawing"));
    generator.setDescription(tr("An SVG drawing created by the SVG Generator "
                                "Example provided with Qt."));

기타 메타 데이터는 title, descriptionresolution 속성을 설정하여 지정할 수 있습니다.

다른 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 출력 버전을 설명합니다.

Constant설명
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

이 속성은 생성된 출력물의 해상도를 보유합니다.

해상도는 인치당 도트 수로 지정되며 SVG 도면의 실제 크기를 계산하는 데 사용됩니다.

함수에 액세스합니다:

int resolution() const
void setResolution(int dpi)

sizeviewBox참조하세요 .

size : QSize

이 속성은 생성된 SVG 드로잉의 크기를 보유합니다.

기본적으로 이 속성은 QSize(-1, -1) 로 설정되어 있으며, 이는 생성기에서 <svg> 요소의 너비 및 높이 속성을 출력하지 않음을 나타냅니다.

참고: 생성기에서 QPainter 이 활성화되어 있는 동안에는 이 속성을 변경할 수 없습니다.

함수 액세스:

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

viewBoxresolution참조하세요 .

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)

SVG 버전 version 을 사용하는 새 생성기를 구축합니다.

이 함수는 Qt 6.5에 도입되었습니다.

[virtual noexcept] QSvgGenerator::~QSvgGenerator()

생성기를 파괴합니다.

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

재구현합니다: QPaintDevice::metric(QPaintDevice::PaintDeviceMetric 메트릭) 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()도 참조하십시오 .

© 2025 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.