| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | 
|---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/opengl/overlay_x11/overlay_x11.doc:1 --> | 
|---|
| 3 | <html> | 
|---|
| 4 | <head> | 
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|---|
| 6 | <title>OpenGL Overlay X11 Example</title> | 
|---|
| 7 | <style type="text/css"><!-- | 
|---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; } | 
|---|
| 9 | a:link { color: #004faf; text-decoration: none } | 
|---|
| 10 | a:visited { color: #672967; text-decoration: none } | 
|---|
| 11 | body { background: #ffffff; color: black; } | 
|---|
| 12 | --></style> | 
|---|
| 13 | </head> | 
|---|
| 14 | <body> | 
|---|
| 15 |  | 
|---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> | 
|---|
| 17 | <tr bgcolor="#E5E5E5"> | 
|---|
| 18 | <td valign=center> | 
|---|
| 19 | <a href="index.html"> | 
|---|
| 20 | <font color="#004faf">Home</font></a> | 
|---|
| 21 | | <a href="classes.html"> | 
|---|
| 22 | <font color="#004faf">All Classes</font></a> | 
|---|
| 23 | | <a href="mainclasses.html"> | 
|---|
| 24 | <font color="#004faf">Main Classes</font></a> | 
|---|
| 25 | | <a href="annotated.html"> | 
|---|
| 26 | <font color="#004faf">Annotated</font></a> | 
|---|
| 27 | | <a href="groups.html"> | 
|---|
| 28 | <font color="#004faf">Grouped Classes</font></a> | 
|---|
| 29 | | <a href="functions.html"> | 
|---|
| 30 | <font color="#004faf">Functions</font></a> | 
|---|
| 31 | </td> | 
|---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>OpenGL Overlay X11 Example</h1> | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | <p> | 
|---|
| 36 | <b>Warning:</b> From version 5.0 onwards, the Qt OpenGL Extension includes | 
|---|
| 37 | direct support for use of OpenGL overlays. For many uses of overlays, | 
|---|
| 38 | this makes the technique described below redundant. See the <a href="opengl-overlay-example.html">overlay</a> example program. The | 
|---|
| 39 | following is a discussion on how to use non-QGL widgets in overlay | 
|---|
| 40 | planes. | 
|---|
| 41 | <p> Overlayrubber: An example program showing how to use Qt and Qt OpenGL | 
|---|
| 42 | Extension with X11 overlay visuals. | 
|---|
| 43 | <p> See <tt>$QTDIR/examples/opengl/overlay_x11</tt> for the source code. | 
|---|
| 44 | <p> Background information for this example can be found in the | 
|---|
| 45 | information on <a href="opengl-x11-overlays.html">overlays</a>. | 
|---|
| 46 | <p> The example program has three main parts: | 
|---|
| 47 | <p> <ol type=1> | 
|---|
| 48 | <li> <em>GearWidget</em> - a normal, simple <a href="qglwidget.html">QGLWidget</a>. This renders the usual | 
|---|
| 49 | gears. It has been modified to print a debug message every time it | 
|---|
| 50 | redraws (renders) itself. Thus, you can easily confirm that drawing in | 
|---|
| 51 | the overlay plane does not cause redrawings in the main plane where | 
|---|
| 52 | the QGLWidget resides. | 
|---|
| 53 | <p> <li> <em>RubberbandWidget</em> - Very simple standard (non-GL) Qt widget that | 
|---|
| 54 | implements rubberband drawing. Designed for use in an overlay plane. | 
|---|
| 55 | It takes the plane's transparent color as a constructor argument and | 
|---|
| 56 | uses that for its background color. Thus, the widget itself will be | 
|---|
| 57 | invisible, only the rubberbands it draws will be visible. | 
|---|
| 58 | <p> <li> <em>main.cpp</em> Creates a GearWidget and a Rubberbandwidget and puts the | 
|---|
| 59 | latter on top of the former. Contains a routine that checks that the | 
|---|
| 60 | default visual is in an overlay plane, and returns the transparent | 
|---|
| 61 | color of that plane. | 
|---|
| 62 | </ol> | 
|---|
| 63 | <p> <h2> Running the Example | 
|---|
| 64 | </h2> | 
|---|
| 65 | <a name="1"></a><p> Start the <tt>overlayrubber</tt> executable. Click and drag with the left | 
|---|
| 66 | mouse button to see rubberband drawing. Observe that the <a href="qglwidget.html">QGLWidget</a> | 
|---|
| 67 | does not redraw itself (no redraw debug messages are output), and yet | 
|---|
| 68 | the image is not destroyed. Marvel at the coolness of X11 overlays! | 
|---|
| 69 | <p> <h2> Using this technique in a real application | 
|---|
| 70 | </h2> | 
|---|
| 71 | <a name="2"></a><p> For clarity, this example program has been kept very simple. Here are | 
|---|
| 72 | some hints for real application usage: | 
|---|
| 73 | <p> <ul> | 
|---|
| 74 | <p> <li> <em>All normal widgets are in the overlay plane.</em> This means that you | 
|---|
| 75 | can put all kinds of Qt widgets (your own or standard Qt widgets) on | 
|---|
| 76 | top of the OpenGL image (widget), e.g. pushbuttons etc., and they can | 
|---|
| 77 | be moved, resized, or removed without destroying the OpenGL image. | 
|---|
| 78 | <p> <li> <em>Using with geometry management.</em> The <a href="qlayout.html">QLayout</a> classes don't permit | 
|---|
| 79 | putting one widget (the overlay) on top of another (the OpenGL | 
|---|
| 80 | widget); that would defy the whole purpose of the automatic layout. | 
|---|
| 81 | The solution is to add just one of them to the QLayout object. Have it | 
|---|
| 82 | keep a pointer to the other (i.e. the <a href="qglwidget.html">QGLWidget</a> knows about its | 
|---|
| 83 | overlay widget or vice versa). Implement the resizeEvent() method of | 
|---|
| 84 | the widget you put in the layout, and make it call setGeometry() on | 
|---|
| 85 | the other widget with its own geometry as parameters, thus keeping the | 
|---|
| 86 | two widgets' geometries synchronized. | 
|---|
| 87 | <p> <li> <em>Using together with <a href="qpalette.html">QPalette</a> and <a href="qcolorgroup.html">QColorGroup</a>.</em> Instead of the | 
|---|
| 88 | simplistic setBackgroundColor( transparentColor ), you can | 
|---|
| 89 | use Qt's QPalette system to make your overlay widgets use | 
|---|
| 90 | transparent color for what you want. This way, the normal Qt widgets | 
|---|
| 91 | can be used as overlays for fancy effects. Just create a palette for | 
|---|
| 92 | them with the transparent color for the relevant color roles, e.g. | 
|---|
| 93 | Background and Base, in the Normal and/or Active modes. This way, you | 
|---|
| 94 | can create see-through QPushButtons etc. | 
|---|
| 95 | </ul> | 
|---|
| 96 | <p> <p>See also <a href="opengl-examples.html">OpenGL Examples</a>. | 
|---|
| 97 |  | 
|---|
| 98 | <!-- eof --> | 
|---|
| 99 | <p><address><hr><div align=center> | 
|---|
| 100 | <table width=100% cellspacing=0 border=0><tr> | 
|---|
| 101 | <td>Copyright © 2007 | 
|---|
| 102 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a> | 
|---|
| 103 | <td align=right><div align=right>Qt 3.3.8</div> | 
|---|
| 104 | </table></div></address></body> | 
|---|
| 105 | </html> | 
|---|