0
我有一個奇怪的錯誤,對QGraphicsObject的QPropertyAnimation非工作。這裏是代碼,Pyqt v.4.8.6,Qt 4.6。正如你所看到的,沒有發生'valueChanged'信號。 這是一個錯誤還是我做錯了什麼?提前致謝!QGraphicsObject與QPropertyAnimation在PyQt
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from functools import partial
class GObject(QGraphicsObject):
def boundingRect(self):
return QRectF(0, 0, 10, 10)
def paint(self, p, *args):
p.drawRect(self.boundingRect())
def animatePos(self, start, end):
print 'Animating..'
anim = QPropertyAnimation(self, 'pos')
anim.setDuration(400)
anim.setStartValue(start)
anim.setEndValue(end)
self.connect(anim, SIGNAL('valueChanged(const QVariant&)'), self.go)
#self.connect(anim, SIGNAL('stateChanged (QAbstractAnimation::State, QAbstractAnimation::State)'),self.ttt)
anim.start() #QAbstractAnimation.DeleteWhenStopped)
def go(self, t):
print t
class Scene_Chooser(QWidget):
def __init__(self, parent = None):
super(Scene_Chooser, self).__init__(parent)
vbox = QVBoxLayout(self)
vbox.setContentsMargins(0, 0, 0, 0)
view = QGraphicsView(self)
self.scene = QGraphicsScene(self)
obj = GObject()
self.scene.addItem(obj)
view.setScene(self.scene)
btn = QPushButton('animate', self)
vbox.addWidget(view)
vbox.addWidget(btn)
btn.clicked.connect(partial(obj.animatePos, QPointF(0,0), QPointF(10, 5)))
非常感謝你,瑪塔!而已! –