c++ - Qt - 需要递归重绘,怎么样?

标签 c++ qt opengl graphics

我有以下代码:

paintGL()
{

    if(mouse_was_clicked)
    {
       ... do the color picking with openGL to identify a clicked element

       ... !!! now I need to call again paintGL() to switch the selected element from the 
              old one to the new one but I can't create a recursive cycle!
    }
    else
    {
       ... normal code to draw the scene and the selected element in red ...
    }
}

如行所示,我需要一种方法来再次调用绘制事件。有没有什么方法可以在不创建潜在活锁的情况下完成此操作?比如推迟新的油漆事件?

最佳答案

如果您的 paintGL() 中的控制流如此简单,只需确保当前在 else block 中的内容在每种情况下都被执行:

void MyWidget::paintGL()
{
    if(mouse_was_clicked)
    {
        ... do the color picking with openGL to identify a clicked element
    }

    ... normal code to draw the scene and the selected element in red ...
}

关于c++ - Qt - 需要递归重绘,怎么样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11595977/

相关文章:

c++ - 画一个不同颜色扇区的圆环

opengl - 显示 2 个半透明对象的公共(public)部分?

java - OpenGL无法绘制线条,但四边形可以工作

c++ - 理解 QGraphicsItemboundingRect 和 shape 方法之间的交互

c++ - 可以在QML中的 map 上绘制带有孔的MapPolygon吗?

c++ - Beagle bone交叉编译动态链接困惑

C++ long long 操作

c++ - 模板运算符重载中的类型冲突

c++ - vc++ 无法解析的外部符号(无法调用构造函数)

qt - 将数据处理与 GUI 分开