PDA

View Full Version : Widgets on top of a QGLWidget



chezifresh
18th December 2009, 21:02
I'm making an OpenGL widget with some Qt controls sitting on top of it. The OpenGL widget is used for playing back images (ie. .mov files) and the controls are playback controls.

The playback controls are parented to a vanilla QWidget (http://doc.trolltech.com/latest/qwidget.html) which is then parented to the QGLWidget (http://doc.trolltech.com/latest/qglwidget.html). I want the vanilla QWidget to have a transparent or partially transparent background so all you can see are the playback controls. I've tried the following but all I get is garbage as the background.


setBackgroundRole(QPalette::Base);
QPalette pal;
pal.setColor(QPalette::Base, QColor(Qt::transparent));
setPalette(pal);Is there a good way to integrate a QWidget into an OpenGL? Any widget attributes or paint engine tricks? Essentially I want to make the playback controls look like they're painted as an overlay in OpenGL.

FYI I do not have a compositing window manager :(

Lendrick
18th December 2009, 23:04
Yes. There's a wiki entry about this here:

http://wiki.qtcentre.org/index.php?title=Accelerate_your_Widgets_with_OpenG L

There's also some sample code to download and compile. This is a bit more complicated than a plain QGLWidget, but it seems to work pretty well.

chezifresh
21st December 2009, 20:29
Yup, that seems like the right way to go. Unfortunately for me I inherited an existing code base and probably can't refactor it to put the OpenGL widget in a graphics view.

I might just have to do what VLC does in Gnome and just have it animate a floating widget above the OpenGL window sans opacity. Thanks for the response, perhaps I can try to refactor the code later.

Lendrick
30th December 2009, 00:29
I actually had an old codebase and managed to refactor it. It's not as bad as you think -- obviously have a backup handy before you attempt it, though.