Hi, I'm trying to draw a rect in myGLWidget; it seems work; but I can see rect while I rotate the scene with mouseMove (and paintGL starts evey time I move mouse). Why this?
Printable View
You can see the rectangle, so what's the problem?
No I can see retangle; I can see only while I rotate scene (an paintGl is called); when I stop mouseMoveEvent ( and so paintGL call), rettangle isn't visible; and in console appear
a message
Where must I call painter.end()?Code:
QPaintDevice: Cannot destroy paint device that is being painted. Be sure to QPainter::end() painters!
thanks
It's hard to tell just from 2 lines of code. What does your mouseMoveEvent() do?
translate the scene and call updateGL() for update the scene; the square apperar only when I pressmouse+move = updateGL()
How do you create and destroy that painter?
Better try creating that painter on the stack every time you need it.
mmm but I need it fixed displayed on myWidgetGL....
Just create the painter on the stack in the method which uses it, this way it will be destroyed in the right time and you won't have to bother with QPainter::end().
Sorry, but how do I create painter on the stack?? But the problem of have fixed rect on my QGLWidget persist....
Thanks
sorry but I tried also this (I insert in paintGL() ) but the rect isn't appear; apper only while I traslate/rotate my scene (when updateGL()); maybe is there something that delete it?mmm; (ok for problem of painter.end()). Thanks
with your code console ask me this: 'painter.begin(this);' adding this istruction seems works , but when I traslate /rotating my scene square disappear (calls to updateGL() ); strange: if I click on my scene (updateGL occurs) rect appear; I see that If I moveMouse with buttonMouse down paintEvent() not occurs; instead If I click only, paintEvent occur();
Furthermore I have QWidget::mouseLeave() where inside there's an updateGL(): when I mouse mouse out, updateGL occurs and rect disappear!
mmmmm....
It looks like QGLWidget repaints are handled in a special way. You might try rendering your scene to a pixmap, painting on that pixmap and then displaying it, but this will affect the performance.
I understand; updateGL(9 doesn't call paint event; update() insted, yes!
I change this below and now rect is visible (but flickering);
But now arise another problem: the update of widget2 is not fuid! I know updateGL() calls paintGL immediately; update() schedule the call to paintGL() for when widgetGL need an update; I suspect that in my multipleView (I can see wid2 and wid3) widget3 is the last drawn; and paintGL() for widget2 starts later than necessay. Can be the truth?Code:
void myMainForm::myUpdateWidgets() { if (this->MultipleView->isShown()){ myWidget2->update(); myWidget3->update(); .......................................... }
How can avoid this? Thanks