OpenGL without using QGLWidget
I would like to use a regular QWidget for my OpenGL drawings, but encounter some problems.
I installed an eventFilter() to capture the paintEvent for the Widget and am doing all my OpenGL drawing code (including swapping buffers) in there.
When I return "true" to stop the event being processed any further, the Widget stays gray.. I can't see my OpenGL stuff at all... when I return "false" it start's to flicker between my own Drawings and the Gray default background.
I also tried to set Attributes like WA_PaintOnScreen and WA_NoSystemBackground, but all they change is that the Widget is no longer gray but black (my OpenGL Clear Color is yellow for test-purposes).
I am pretty sure I am missing something important like an "erasing the background"-event or something, but can't find anything :(
Any help would be realy appreciated!
PS: I don't want to use the QGLWidget because we already have our whole Engine including initialisation of OpenGL etc.. all I want to do is to use a QWidget's HWND/HDC (on Windows) as Rendertarget..
Adrien Leravat last edited by
You can use a QGLWidget and call your own full OpenGL initialization/paint stuff from within it (initializeGL, paintGL, etc.). You'd just need to give QGLWidget a pointer to your engine and call your own methods from QGLWidget ones. I did something similar myself previously and didn't encountered any issues.
Using a regular QWidget to render OpenGL directly on it is surely a harder thing to achieve. Maybe having a look at QGLWidget source would help a bit, if you haven't done so.
Good luck anyway.
thanks for your reply but we realy don't want to use the QGLWidget.. fancy politics here.. :)
I already looked at the source of QGLWidget and found out it's setting the WindowFlag Qt::MSWindowsOwnDC on creating and is setting the following Attributes:
setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); setAutoFillBackground(true);
I did the same for our Widget, but.. no luck :(
BUT, I noticed our Widget is not just black, actually it's flickering between Black and Yellow (Yellow is our OpenGL Clear Color) - but only when I move the widget to the top of the Screen.. very strange..
And unfortunately I don't see any big difference between our code and the one of QGLWidget.. But there must be a tiny difference hidden somewhere :(
utcenter last edited by
You might want to check "QWindow":http://qt-project.org/doc/qt-5.0/qtgui/qwindow.html if you are using Qt5 - it offers an OpenGL context without the overhead of QtWidgets.
Adrien Leravat last edited by
Did you tried to set the "WA_OpaqueBackground" attribute, andare you sure the original QWidget::paintEvent is inhibited ? (just to be sure :) )
I got it to work - but not sure if it's correct.
I called my own OpenGL-Draw code in the QEvent::Paint and returned true. Then I called widget.repaint() in a loop so the Paint-Event get's called again, this caused the flickering.
Now I directly call my OpenGL-Draw method instead of the widget.repaint() - this solved the issues :)
But, since the repaint-event will be called from time to time from the System I am a bit unsure if I will get a black flashing screen each time.. have to try this out.
uwydoc last edited by
thanks! it solved the flicker problem i encountered last night.
actually i had turned off Qt' paint engine, but it made no difference when in fullscreen mode, so i turned it off some time later. however, in windowed mode, it makes a huge difference.
[quote author="Adrien Leravat" date="1359051022"]are you sure the original QWidget::paintEvent is inhibited ? (just to be sure :) )[/quote]