• 3179阅读
  • 1回复

[提问]mapToParent(dx,dy)包含坐标自增吗? [复制链接]

上一主题 下一主题
离线oceanwind
 

只看楼主 倒序阅读 楼主  发表于: 2016-07-23
看到书上蝴蝶飞舞的例子。其中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中的坐标啊.
离线6gongzi

只看该作者 1楼 发表于: 2016-07-25
这里产生的是随机生成的新坐标
快速回复
限100 字节
 
上一个 下一个