看到书上蝴蝶飞舞的例子。其中timer调用的的函数:
void Butterfly::timerEvent(QTimerEvent *)
{
//边界控制
qreal edgex=scene()->sceneRect().right()+boundingRect().width()/2;
qreal edgetop=scene()->sceneRect().top()+boundingRect().height()/2;
qreal edgebottom=scene()->sceneRect().bottom()+boundingRect(). height()/2;
if(pos().x()>=edgex)
setPos(scene()->sceneRect().left(),pos().y());
if(pos().y()<=edgetop)
setPos(pos().x(),scene()->sceneRect().bottom());
if(pos().y()>=edgebottom)
setPos(pos().x(),scene()->sceneRect().top());
angle+=(qrand()%10)/20.0;
qreal dx=fabs(sin(angle*PI)*10.0);
qreal dy=(qrand()%20)-10.0;
setPos(mapToParent(dx,dy));
}
最后一句 setPos(mapToParent(dx,dy)); 包含在map到SCENE坐标时在SCENE坐标中自增其原坐标吗?
看定议只是返回在SCENE中的坐标啊.