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

标签 c++ qt

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

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/

相关文章:

c++ - 核心文件的大小是否反射(reflect)了应用程序崩溃时的内存使用情况?

c++ - 是否有合法的方式从 gsl::not_null<T> 转移?

qt - 如何在 Qt 中拥有可拆卸的工具窗口

c++ - 将析构函数中的关键函数放在 "enhance atomicity"中?

c++ - 如何在 Windows 上获取用户主目录?

c++ - 间接运算符是否会更改内存表示?

c++ - 试图在 Qt QTreeView 中选择整行

c++ - QList 模板化结构

c++ - Qt 调试器控制台看不到调试 session

c - 将 libpq-fe.h 添加到 qt 现有项目