gpt4 book ai didi

c++ - 有没有办法停止 QGraphicsScene?

转载 作者:行者123 更新时间:2023-11-28 05:10:34 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com