我有一个从某个位置向上移动的椭圆。
void Equalizer::advance(int phase)
{
if(!phase) return;
QPointF location = this->pos();
setPos(mapToParent(0 , -(speed)));
}
虽然我希望它在到达某个 y 坐标时停止移动。我该怎么做?
最佳答案
不更新它的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)));
}
关于c++ - 有没有办法停止 QGraphicsScene?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43592822/