有没有办法阻止QGraphicsScene?

时间:2017-04-24 16:01:56

标签: c++ qt

我有一个从某个位置向上移动的椭圆。

void Equalizer::advance(int phase)
{
    if(!phase) return;

    QPointF location = this->pos();
    setPos(mapToParent(0 , -(speed)));
 }

虽然我希望它在达到某个y坐标时停止移动。我该怎么做?

1 个答案:

答案 0 :(得分:1)

当达到指定的y坐标

时,不要更新其y位置
void Equalizer::advance(int phase)
{
    if(!phase) return;

    QPointF location = this->pos();

    if(location.y() <= specifiedY)
    {
        //If the speed at which the ellipse is moving is great enough to take it beyond the specifiedY, set it to the specifiedY before the return.
        setPos(pos().x(), specifiedY); // assuming specifiedY is in scene coordinates
        return;
    }        
    setPos(mapToParent(0 , -(speed)));
 }