SVG 파일 렌더링
SVG 도면은 QWidget 이나 QImage 과 같은 모든 QPaintDevice 하위 클래스에 렌더링할 수 있습니다. SVG 파일을 렌더링하는 가장 쉬운 방법은 QSvgWidget 또는 QSvgRenderer 를 사용하는 것입니다.
QSvgWidget 사용
QSvgWidget 는 SVG 파일을 표시하는 데 편리한 위젯을 제공합니다.
#include <QApplication>
#include <QSvgWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSvgWidget svgWidget(QStringLiteral(":/images/example.svg"));
svgWidget.setGeometry(100, 100, 400, 400);
svgWidget.show();
return app.exec();
}생성 후 SVG 파일을 불러올 수도 있습니다:
#include <QApplication>
#include <QSvgWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSvgWidget *svgWidget = new QSvgWidget;
svgWidget->load(QStringLiteral(":/images/example.svg"));
svgWidget->show();
return app.exec();
}QSvgRenderer 사용
QSvgRenderer 를 사용하여 SVG 콘텐츠를 임의의 QPaintDevice 에 렌더링할 수 있습니다.
#include <QApplication>
#include <QSvgRenderer>
#include <QImage>
#include <QPainter>
#include <QLabel>
#include <QPixmap>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSvgRenderer renderer(QStringLiteral(":/images/example.svg"));
if (renderer.isValid()) {
QImage image(400, 400, QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent);
QPainter painter(&image);
renderer.render(&painter);
QLabel label;
label.setPixmap(QPixmap::fromImage(image));
label.resize(400, 400);
label.show();
return app.exec();
}
return 1;
}또한 QSvgRenderer 를 사용하여 사용자 정의 위젯의 paint 이벤트에서 SVG를 직접 렌더링할 수도 있습니다:
// In your widget's header file:
#include <QSvgRenderer>
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent = nullptr)
: QWidget(parent), renderer(QStringLiteral(":/images/example.svg")) {}
protected:
void paintEvent(QPaintEvent *) override {
QPainter painter(this);
renderer.render(&painter);
}
private:
QSvgRenderer renderer;
};이러한 방법을 통해 QWidget 및 QImage 를 포함하여 Qt에서 지원하는 모든 페인트 장치에 SVG 파일을 렌더링할 수 있습니다.
렌더링 옵션
QSvgRenderer 는 ` QtSvg::Option ` 열거형을 통해 ` options ` 렌더링 옵션을 제공합니다. 이 옵션을 사용하면 SVG 파일이 파싱되고 렌더링되는 방식을 제어할 수 있습니다.
애니메이션 SVG 파일 렌더링
Qt SVG 모듈은 애니메이션이 포함된 SVG 파일의 렌더링을 지원합니다. 애니메이션 SVG를 다루는 방법에 대한 자세한 내용은 QSvgRenderer 클래스 문서를 참조하십시오.
Qt의 벡터 이미지 형식 및 확장 기능항목도 참조하십시오 .
© 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.