QSvgRenderer Class
The QSvgRenderer class is used to draw the contents of SVG files onto paint devices. More...
Header: | #include <QSvgRenderer> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Svg) target_link_libraries(mytarget PRIVATE Qt6::Svg) |
qmake: | QT += svg |
Note: All functions in this class are reentrant.
Properties
- aspectRatioMode : Qt::AspectRatioMode
- framesPerSecond : int
- viewBox : QRectF
Public Functions
virtual | ~QSvgRenderer() |
bool | animated() const |
Qt::AspectRatioMode | aspectRatioMode() const |
QSize | defaultSize() const |
int | framesPerSecond() const |
bool | isValid() const |
void | setAspectRatioMode() |
void | setFramesPerSecond() |
void | setViewBox() |
void | setViewBox() |
QRect | viewBox() const |
QRectF | viewBoxF() const |
Signals
void | repaintNeeded() |
Detailed Description
Using QSvgRenderer, Scalable Vector Graphics (SVG) can be rendered onto any QPaintDevice subclass, including QWidget, QImage, and QGLWidget.
QSvgRenderer provides an API that supports basic features of SVG rendering, such as loading and rendering of static drawings, and more interactive features like animation. Since the rendering is performed using QPainter, SVG drawings can be rendered on any subclass of QPaintDevice.
SVG drawings are either loaded when an QSvgRenderer is constructed, or loaded later using the load() functions. Data is either supplied directly as serialized XML, or indirectly using a file name. If a valid file has been loaded, either when the renderer is constructed or at some later time, isValid() returns true; otherwise it returns false. QSvgRenderer provides the render() slot to render the current document, or the current frame of an animated document, using a given painter.
The defaultSize() function provides information about the amount of space that is required to render the currently loaded SVG file. This is useful for paint devices, such as QWidget, that often need to supply a size hint to their parent layout. The default size of a drawing may differ from its visible area, found using the viewBox property.
Animated SVG drawings are supported, and can be controlled with a simple collection of functions and properties:
- The animated() function indicates whether a drawing contains animation information.
- The framesPerSecond property contains the rate at which the animation plays.
Finally, the QSvgRenderer class provides the repaintNeeded() signal which is emitted whenever the rendering of the document needs to be updated.
See also QSvgWidget, Qt SVG C++ Classes, and QPicture.
Property Documentation
aspectRatioMode : Qt::AspectRatioMode
how rendering adheres to the SVG view box aspect ratio
The accepted modes are:
- Qt::IgnoreAspectRatio (the default): the aspect ratio is ignored and the rendering is stretched to the target bounds.
- Qt::KeepAspectRatio: rendering is centered and scaled as large as possible within the target bounds while preserving aspect ratio.
Access functions:
Qt::AspectRatioMode | aspectRatioMode() const |
void | setAspectRatioMode() |
framesPerSecond : int
This property holds the number of frames per second to be shown
The number of frames per second is 0 if the current document is not animated.
Access functions:
int | framesPerSecond() const |
void | setFramesPerSecond() |
See also animated().
viewBox : QRectF
This property holds the rectangle specifying the visible area of the document in logical coordinates
Access functions:
QRectF | viewBoxF() const |
void | setViewBox() |
void | setViewBox() |
Member Function Documentation
[virtual]
QSvgRenderer::~QSvgRenderer()
Destroys the renderer.
bool QSvgRenderer::animated() const
Returns true if the current document contains animated elements; otherwise returns false.
See also framesPerSecond().
QSize QSvgRenderer::defaultSize() const
Returns the default size of the document contents.
bool QSvgRenderer::isValid() const
Returns true if there is a valid current document; otherwise returns false.
[signal]
void QSvgRenderer::repaintNeeded()
This signal is emitted whenever the rendering of the document needs to be updated, usually for the purposes of animation.
QRect QSvgRenderer::viewBox() const
Returns viewBoxF().toRect().
See also setViewBox() and viewBoxF().