PDA

View Full Version : Using QWidgets on QGLWidget for 3D game interface



Statix
18th March 2008, 21:16
I'm experimenting with using Qt as the GUI back-end for a 3D game but during my experiments with QGLWidget I've ran into some issues that hopefully some of you can help resolve or offer better implementation ideas.

Approach 1: Create a QGLWidget, and use it as the parent of regular QWidgets, let Qt manage drawing.

This seems to achieve the general idea of using QWidgets as an overlay for a GL window however I am unsure on the correct method for drawing. For the game loop I would ideally update the GL window via timer using updateGL() and have the widgets draw afterward (with transparency). So far I have been able to draw opaque widgets but I have been unable to make a widget draw with either background brush transparency or full transparency (I'm probably doing it wrong). Another concern is the speed of drawing the Widgets ontop as I am unaware of the internals going on with Qt and GL (is it using an internal overlay?)


Approach 2: Create QGLWindow, Widgets(hidden), draw widgets to dynamicTextures.

Another idea I had was to create a Widget and draw to a dynamic texture applied to a GL surface. This could be done using by changing the widget paintEvent or using grabWidget somewhere. The mouse events in the GLWidget would need translated and redirected to the corresponding Widgets depicted by the textured GL surface. This probably doesn't solve the transparency issue either, however making rects in GL transparent is easy, but not the best way as I may not want QLabel text to be transparent, just the background.

If there is some way I could put a Widget in a GLWidget, tell it not to draw (instead draw to the dynamicTexture), but still handle mouse clicks for the area it *would* draw to, then that would just be peachy :D


Approach 1 is the simplest but Approach 2 is most likely way faster.
Any help/ideas would be appreciated.

ConfusedSushi
18th March 2008, 21:25
i had the same problem and solved it using something like your second approach.

it is working, but it is not perfect, specially for qt < 4.4, i think because of the new introduced alien widgets. for qt 4.4 i get usable results.

i am likely to share my code, with the hope of getting better results.

please leave a private message, if you are interested.

qtari
15th February 2010, 13:52
Hello, I am a newbee in QT. I need to draw a QTextEdit control on top of a work area which is a QGLWidget. I would appreciate if you share your code on this problem with me. I will test it if it is applicable and share my experience with you. I hope that many will benefit from it.
Thank you in advance! send it to ariunaa_bertelsen@hotmail.com

qtari
15th February 2010, 14:05
Hello, I am a newbee in QT. I need to draw a QTextEdit control on top of a work area which is a QGLWidget. I would appreciate if you share your code on this problem with me. I will test it if it is applicable and share my experience with you. I hope that many will benefit from it.
Thank you in advance! send it to ariunaa_bertelsen@hotmail.com