QGraphicsSvgItem Class
QGraphicsSvgItem 클래스는 SVG 파일의 내용을 렌더링하는 데 사용할 수 있는 QGraphicsItem 입니다. 더 보기...
헤더: | #include <QGraphicsSvgItem> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS SvgWidgets) target_link_libraries(mytarget PRIVATE Qt6::SvgWidgets) |
qmake: | QT += svgwidgets |
상속합니다: | QGraphicsObject |
속성
- elementId : QString
- maximumCacheSize : QSize
공용 함수
QGraphicsSvgItem(QGraphicsItem *parent = nullptr) | |
QGraphicsSvgItem(const QString &fileName, QGraphicsItem *parent = nullptr) | |
QString | elementId() const |
QSize | maximumCacheSize() const |
QSvgRenderer * | renderer() const |
void | setElementId(const QString &id) |
void | setMaximumCacheSize(const QSize &size) |
void | setSharedRenderer(QSvgRenderer *renderer) |
재구현된 공용 함수
virtual QRectF | boundingRect() const override |
virtual void | paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override |
virtual int | type() const override |
상세 설명
QGraphicsSvgItem 은 SVG 파일을 QGraphicsView 에 렌더링하는 방법을 제공합니다. 생성자에 렌더링할 SVG 파일을 전달하거나 공유 QSvgRenderer 를 명시적으로 설정하여 QGraphicsSvgItem을 생성할 수 있습니다.
QGraphicsSvgItem에 QSvgRenderer 을 설정해도 해당 항목이 렌더러의 소유권이 되는 것은 아니므로 setSharedRenderer() 메서드를 사용하는 경우 QSvgRenderer 객체의 수명이 적어도 QGraphicsSvgItem의 수명만큼 길도록 해야 합니다.
QGraphicsSvgItem은 setElementId 를 통해 SVG 파일의 일부만 렌더링하는 방법을 제공합니다. setElementId() 메서드가 호출되면 전달된 ID를 가진 SVG 요소(및 그 자식)만 렌더링됩니다. 이를 통해 여러 개의 개별 요소가 포함된 대용량 SVG 파일을 선택적으로 렌더링할 수 있는 편리한 방법을 제공합니다. 예를 들어 다음 코드는 전체 카드 덱이 포함된 SVG 파일에서 조커만 렌더링합니다:
QSvgRenderer *renderer = new QSvgRenderer(QLatin1String("SvgCardDeck.svg")); QGraphicsSvgItem *black = new QGraphicsSvgItem(); QGraphicsSvgItem *red = new QGraphicsSvgItem(); black->setSharedRenderer(renderer); black->setElementId(QLatin1String("black_joker")); red->setSharedRenderer(renderer); red->setElementId(QLatin1String("red_joker"));
항목의 크기는 항목 변환 매트릭스를 직접 조작하여 설정할 수 있습니다.
기본적으로 SVG 렌더링은 아이템 표시 속도를 높이기 위해 QGraphicsItem::DeviceCoordinateCache 모드를 사용하여 캐시됩니다. QGraphicsItem::setCacheMode () 메서드에 QGraphicsItem::NoCache 을 전달하여 캐싱을 비활성화할 수 있습니다.
QSvgWidget, Qt SVG C++ Classes, QGraphicsItem, 및 QGraphicsView 을 참조하세요.
속성 문서
elementId : QString
이 속성은 요소의 XML ID를 보유합니다.
액세스 함수:
QString | elementId() const |
void | setElementId(const QString &id) |
maximumCacheSize : QSize
이 속성은 이 항목에 대한 장치 좌표 캐시의 최대 크기를 보유합니다.
액세스 함수:
QSize | maximumCacheSize() const |
void | setMaximumCacheSize(const QSize &size) |
멤버 함수 문서
QGraphicsSvgItem::QGraphicsSvgItem(QGraphicsItem *parent = nullptr)
주어진 parent 으로 새 SVG 항목을 생성합니다.
QGraphicsSvgItem::QGraphicsSvgItem(const QString &fileName, QGraphicsItem *parent = nullptr)
지정된 parent 으로 새 항목을 생성하고 지정된 fileName 으로 SVG 파일의 내용을 로드합니다.
[override virtual]
QRectF QGraphicsSvgItem::boundingRect() const
재구현합니다: QGraphicsItem::boundingRect() const.
이 항목의 경계 사각형을 리턴합니다.
QString QGraphicsSvgItem::elementId() const
현재 렌더링 중인 요소의 XML ID를 반환합니다. 전체 파일이 렌더링 중인 경우 빈 문자열을 반환합니다.
참고: elementId 속성에 대한 게터 함수입니다.
setElementId()도 참조하세요 .
QSize QGraphicsSvgItem::maximumCacheSize() const
이 항목에 대한 장치 좌표 캐시의 현재 최대 크기를 반환합니다. 항목이 QGraphicsItem::DeviceCoordinateCache 모드를 사용하여 캐시되는 경우 장치 좌표에서 항목의 확장이 최대 크기보다 크면 캐시가 무시됩니다.
QPixmapCache::cacheLimit()는 전체 캐시의 누적 한계를 제공하는 반면, maximumCacheSize()는 이 특정 항목의 최대 캐시 크기를 나타냅니다.
참고: maximumCacheSize 속성에 대한 게터 함수입니다.
setMaximumCacheSize() 및 QGraphicsItem::cacheMode()도 참조하세요 .
[override virtual]
void QGraphicsSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr)
재구현합니다: QGraphicsItem::paint(QPainter *페인터, const Q스타일옵션그래픽아이템 *옵션, Q위젯 *위젯).
QSvgRenderer *QGraphicsSvgItem::renderer() const
현재 사용 중인 QSvgRenderer 을 반환합니다.
void QGraphicsSvgItem::setElementId(const QString &id)
요소의 XML ID를 id 로 설정합니다.
참고: 속성에 대한 세터 함수 elementId.
elementId()도 참조하세요 .
void QGraphicsSvgItem::setMaximumCacheSize(const QSize &size)
항목의 최대 장치 좌표 캐시 크기를 size 로 설정합니다. 항목이 QGraphicsItem::DeviceCoordinateCache 모드를 사용하여 캐시되는 경우 장치 좌표에서 항목의 확장자가 size 보다 크면 캐싱이 우회됩니다.
이 캐시는 렌더링 결과를 캐시하는 데 사용되는 QPixmap 에 해당합니다. 전체 캐시에 제한을 설정하려면 QPixmapCache::setCacheLimit()를 사용하고 개별 항목의 캐시 크기를 설정할 때는 setMaximumCacheSize()를 사용합니다.
참고: 속성에 대한 설정자 함수 maximumCacheSize.
maximumCacheSize() 및 QGraphicsItem::cacheMode()도 참조하세요 .
void QGraphicsSvgItem::setSharedRenderer(QSvgRenderer *renderer)
renderer 을 항목의 공유 QSvgRenderer 로 설정합니다. 이 메서드를 사용하면 여러 항목에서 동일한 QSvgRenderer 을 공유할 수 있습니다. 즉, SVG 파일은 한 번만 구문 분석됩니다. 이 메서드로 전달된 QSvgRenderer 은 이 항목이 사용되는 동안 계속 존재해야 합니다.
[override virtual]
int QGraphicsSvgItem::type() const
재구현합니다: QGraphicsItem::type() const.
© 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.