有没有办法停止QGraphicsScene?
问题描述:
我有一个从某个位置向上移动的椭圆。有没有办法停止QGraphicsScene?
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)));
}
+0
但是不会导致QGraphicsScene在无效的情况下继续调用这个无限循环吗? –
+0
@JackNickolson,试试看看会发生什么; O) – TheDarkKnight
你为什么不使用QPropertyAnimation呢?处理几乎所有你能想到的事情都会好得多。 – phyatt
@phyatt,'better'是主观的。如果在游戏中处理玩家对象的实时移动,基于用户输入,这不是我想要使用的。 – TheDarkKnight