0

我有以下代码:

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 ...
    }
}

正如线条所暗示的那样,我需要一种方法来再次调用绘制事件。有没有办法在不产生潜在活锁的情况下实现这一点?比如推迟一个新的绘画活动?

4

2 回答 2

3

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

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 ...
}
于 2012-07-21T21:47:04.430 回答
3

很难准确地说出你在这里做什么。

如果您在paintGL 检测到已单击鼠标按钮时尝试设置显示小部件(颜色选择器),则您混淆了事件。您应该为处理鼠标单击进行单独的操作,该操作设置标志/变量并触发重绘。IE,将鼠标事件处理移出重绘回调。

I could easily have misunderstood your problem here, however... if so I apologize.

As a general rule, though, if you find yourself needing a recursive repaint in QT, you're probably working against, rather than with, the system.

于 2012-07-21T21:51:39.550 回答