QSvgRendererclass is used to draw the contents of SVG files onto paint devices. 更多 …
def
animated
()
def
animationDuration
()
def
aspectRatioMode
()
def
boundsOnElement
(id)
def
currentFrame
()
def
defaultSize
()
def
elementExists
(id)
def
framesPerSecond
()
def
isValid
()
def
matrixForElement
(id)
def
setAspectRatioMode
(mode)
def
setCurrentFrame
(arg__1)
def
setFramesPerSecond
(num)
def
setViewBox
(viewbox)
def
setViewBox
(viewbox)
def
transformForElement
(id)
def
viewBox
()
def
viewBoxF
()
def
repaintNeeded
()
使用
QSvgRenderer, Scalable Vector Graphics (SVG) can be rendered onto anyQPaintDevicesubclass, includingQWidget,QImage,和QGLWidget.
QSvgRendererprovides 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 usingQPainter, SVG drawings can be rendered on any subclass ofQPaintDevice.SVG drawings are either loaded when an
QSvgRendereris constructed, or loaded later using theload()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.QSvgRendererprovides therender()slot to render the current document, or the current frame of an animated document, using a given painter.
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 asQWidget, 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 theviewBox特性。Animated SVG drawings are supported, and can be controlled with a simple collection of functions and properties:
animated()function indicates whether a drawing contains animation information.
framesPerSecondproperty contains the rate at which the animation plays.Finally, the
QSvgRendererclass provides therepaintNeeded()signal which is emitted whenever the rendering of the document needs to be updated.另请参阅
QSvgWidgetQt SVG C++ 类 SVG 查看器范例QPicture
QSvgRenderer
(
[
parent=None
]
)
¶
QSvgRenderer(contents[, parent=None])
QSvgRenderer(contents[, parent=None])
QSvgRenderer(filename[, parent=None])
- param parent
QObject- param contents
QXmlStreamReader- param filename
unicode
Constructs a new renderer with the given
parent
.
Constructs a new renderer with the given
parent
and loads the SVG data using the stream reader specified by
contents
.
PySide2.QtSvg.QSvgRenderer.
animated
(
)
¶
bool
Returns true if the current document contains animated elements; otherwise returns false.
另请参阅
PySide2.QtSvg.QSvgRenderer.
animationDuration
(
)
¶
int
Returns the number of frames in the animation, or 0 if the current document is not animated.
PySide2.QtSvg.QSvgRenderer.
aspectRatioMode
(
)
¶
AspectRatioMode
另请参阅
PySide2.QtSvg.QSvgRenderer.
boundsOnElement
(
id
)
¶
id – unicode
QRectF
Returns bounding rectangle of the item with the given
id
. The transformation matrix of parent elements is not affecting the bounds of the element.
PySide2.QtSvg.QSvgRenderer.
currentFrame
(
)
¶
int
PySide2.QtSvg.QSvgRenderer.
defaultSize
(
)
¶
QSize
Returns the default size of the document contents.
PySide2.QtSvg.QSvgRenderer.
elementExists
(
id
)
¶
id – unicode
bool
Returns true if the element with the given
id
exists in the currently parsed SVG file and is a renderable element.
Note: this method returns true only for elements that can be rendered. Which implies that elements that are considered part of the fill/stroke style properties, e.g. radialGradients even tough marked with “id” attributes will not be found by this method.
PySide2.QtSvg.QSvgRenderer.
framesPerSecond
(
)
¶
int
另请参阅
PySide2.QtSvg.QSvgRenderer.
isValid
(
)
¶
bool
Returns true if there is a valid current document; otherwise returns false.
PySide2.QtSvg.QSvgRenderer.
load
(
contents
)
¶
contents
–
QXmlStreamReader
bool
Loads the specified SVG in
contents
,返回 true 若内容被成功剖析;否则返回 false。
The reader will be used from where it currently is positioned. If
contents
is
null
, behavior is undefined.
PySide2.QtSvg.QSvgRenderer.
load
(
contents
)
¶
contents
–
QByteArray
bool
PySide2.QtSvg.QSvgRenderer.
load
(
filename
)
¶
filename – unicode
bool
PySide2.QtSvg.QSvgRenderer.
matrixForElement
(
id
)
¶
id – unicode
QMatrix
注意
此函数被弃用。
使用
transformForElement()
代替。
Returns the transformation matrix for the element with the given
id
. The matrix is a product of the transformation of the element’s parents. The transformation of the element itself is not included.
To find the bounding rectangle of the element in logical coordinates, you can apply the matrix on the rectangle returned from
boundsOnElement()
.
另请参阅
PySide2.QtSvg.QSvgRenderer.
render
(
p
,
elementId
[
,
bounds=QRectF()
]
)
¶
p
–
QPainter
elementId – unicode
bounds
–
QRectF
Renders the given element with
elementId
using the given
painter
on the specified
bounds
. If the bounding rectangle is not specified the SVG element is mapped to the whole paint device.
PySide2.QtSvg.QSvgRenderer.
render
(
p
)
¶
p
–
QPainter
Renders the current document, or the current frame of an animated document, using the given
painter
.
PySide2.QtSvg.QSvgRenderer.
render
(
p
,
bounds
)
¶
p
–
QPainter
bounds
–
QRectF
Renders the current document, or the current frame of an animated document, using the given
painter
on the specified
bounds
within the painter. If
bounds
is not empty, the output will be scaled to fill it, ignoring any aspect ratio implied by the SVG.
PySide2.QtSvg.QSvgRenderer.
repaintNeeded
(
)
¶
PySide2.QtSvg.QSvgRenderer.
setAspectRatioMode
(
mode
)
¶
mode
–
AspectRatioMode
另请参阅
PySide2.QtSvg.QSvgRenderer.
setCurrentFrame
(
arg__1
)
¶
arg__1
–
int
PySide2.QtSvg.QSvgRenderer.
setFramesPerSecond
(
num
)
¶
num
–
int
另请参阅
PySide2.QtSvg.QSvgRenderer.
setViewBox
(
viewbox
)
¶
viewbox
–
QRect
PySide2.QtSvg.QSvgRenderer.
setViewBox
(
viewbox
)
¶
viewbox
–
QRectF
PySide2.QtSvg.QSvgRenderer.
transformForElement
(
id
)
¶
id – unicode
QTransform
Returns the transformation matrix for the element with the given
id
. The matrix is a product of the transformation of the element’s parents. The transformation of the element itself is not included.
To find the bounding rectangle of the element in logical coordinates, you can apply the matrix on the rectangle returned from
boundsOnElement()
.
另请参阅
PySide2.QtSvg.QSvgRenderer.
viewBox
(
)
¶
QRect
返回
viewBoxF()
.toRect().
另请参阅
PySide2.QtSvg.QSvgRenderer.
viewBoxF
(
)
¶
QRectF