2012-07-21 30 views
0

我有以下代码:Qt - 需要递归重绘,怎么样?

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

随着线提示,我需要一种方法来再次呼吁油漆事件..有没有办法做到这一点,而无需创建一个潜在的活锁?像推迟一个新的绘画事件?

+0

没有深入了解你在做什么......你可以设置一个标志,以便当它再次回来时,你可以错误的标志,并防止递归? – jdi 2012-07-21 21:30:58

回答

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

我是一个白痴,我没有想到过。谢谢! – 2012-07-22 10:30:45

3

这是一个有点很难说什么你”重新在这里做。

如果您尝试在paintGL检测到鼠标按钮被点击时设置显示小部件(颜色选择器),则会混淆您的事件。你应该做一个单独的动作来处理鼠标点击,这会设置标志/变量并触发重绘。 IE,将鼠标事件处理移出repaint回调。

我很容易在这里误解了你的问题,但是...如果是的话,我表示歉意。一般来说,如果你发现自己需要在QT中进行递归重绘,那么你可能是在与系统打交道,而不是在系统中工作。

+0

不是我正在寻找的(更简单),但感谢您的帮助和+1的努力 – 2012-07-22 10:31:09