这是 PySide 中的一个完整应用程序,它在屏幕上显示一个(可能是动画的)SVG 文件:
import sys
from PySide import QtCore, QtGui, QtSvg
app = QtGui.QApplication(sys.argv)
widget = QtSvg.QSvgWidget('animation.svg')
widget.show()
app.exec_()
这是另一个使用图形视图框架为奇怪的矢量形状设置动画的示例:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
app = QApplication(sys.argv)
path = QPainterPath()
path.quadTo(0,20, 20,20)
path.lineTo(10,10)
item = QGraphicsPathItem(path)
timer = QTimeLine(5000)
timer.setFrameRange(0, 100)
ani = QGraphicsItemAnimation()
ani.setItem(item)
ani.setTimeLine(timer)
ani.setPosAt(1, QPointF(200,200))
ani.setRotationAt(1, 360)
ani.setScaleAt(1, 3,3)
scene = QGraphicsScene(0,0, 300,300)
scene.addItem(item)
view = QGraphicsView(scene)
view.setRenderHints(QPainter.Antialiasing)
view.show()
timer.start()
app.exec_()