我有以下代码:
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 ...
}
}
正如线条所示,我需要一种方法再次调用paint事件..有没有办法在不创建潜在的活锁的情况下完成此操作?有什么比推迟新的油漆事件?
答案 0 :(得分: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 ...
}
答案 1 :(得分:3)
要确切地告诉你在这里做什么有点难。
如果您在paintGL检测到鼠标按钮被点击时尝试设置显示窗口小部件(颜色选择器),则会混淆您的事件。您应该为处理鼠标点击单独执行操作,鼠标点击设置标记/变量并触发重绘。 IE,将鼠标事件处理移出重绘回调。
我很容易在这里误解你的问题,但是......如果是的话,我道歉。
但是,作为一般规则,如果您发现自己需要在QT中进行递归重绘,那么您可能正在反对而不是使用系统。