PyQt:QGraphicsItemAnimation与setPosA

2024-05-19 05:06:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个小问题,因为我无法通过如下方式重写setPos方法来创建一个简单的setPos动画:

def setPos(self, pos):                                                                                                                                                                                          
    print('from %s to %s' % (self.scenePos(), pos))                                                                                                                                                             
    timer = QTimeLine(5000)                                                                                                                                                                                     
    timer.setFrameRange(0, 100)                                                                                                                                                                                 
    animation = QGraphicsItemAnimation()                                                                                                                                                                        
    animation.setItem(self)                                                                                                                                                                                     
    animation.setTimeLine(timer)                                                                                                                                                                                
    x_step = (pos - self.scenePos()).x() / 200                                                                                                                                                                  
    y_step = (pos - self.scenePos()).y() / 200                                                                                                                                                                  
    for i in range(200):                                                                                                                                                                                        
        animation.setPosAt(i/200, self.scenePos() + QPointF(i * x_step, i * y_step))                                                                                                                            
    timer.start()    

提前谢谢,b52


Tags: to方法fromposselfdefstep方式
2条回答

@robe:QPropertyAnimation要求声明类是一个QObject,我相信QGraphicsItem不是。在

为什么不使用QPropertyAnimation?。使用这个类,您可以为对象的任何属性创建动画。在

 QPropertyAnimation * animationPos = new QPropertyAnimation(Object, propertyName);

  animationPos->setDuration(miliseconds);
  animationPos->setStarValue(startValueForProperty);
  animationsPos->setEndValue(endValueForProperty);

你应该努力避免很多冲突。在

相关问题 更多 >

    热门问题