summaryrefslogtreecommitdiffstats
path: root/doc/html/opengl-overlay-x11-example.html
blob: 6bc51362a13c996fb3931f3e8b1d49eedf7e9625 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/opengl/overlay_x11/overlay_x11.doc:1 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>OpenGL Overlay X11 Example</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<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>

   
<p> 
<b>Warning:</b> From version 5.0 onwards, the Qt OpenGL Extension includes
direct support for use of OpenGL overlays. For many uses of overlays,
this makes the technique described below redundant. See the <a href="opengl-overlay-example.html">overlay</a> example program. The
following is a discussion on how to use non-QGL widgets in overlay
planes.
<p> Overlayrubber: An example program showing how to use Qt and Qt OpenGL
Extension with X11 overlay visuals.
<p> See <tt>$QTDIR/examples/opengl/overlay_x11</tt> for the source code.
<p> Background information for this example can be found in the
information on <a href="opengl-x11-overlays.html">overlays</a>. 
<p> The example program has three main parts:
<p> <ol type=1>
<li> <em>GearWidget</em> - a normal, simple <a href="qglwidget.html">QGLWidget</a>. This renders the usual
gears. It has been modified to print a debug message every time it
redraws (renders) itself. Thus, you can easily confirm that drawing in
the overlay plane does not cause redrawings in the main plane where
the QGLWidget resides.
<p> <li> <em>RubberbandWidget</em> - Very simple standard (non-GL) Qt widget that
implements rubberband drawing. Designed for use in an overlay plane.
It takes the plane's transparent color as a constructor argument and
uses that for its background color. Thus, the widget itself will be
invisible, only the rubberbands it draws will be visible.
<p> <li> <em>main.cpp</em> Creates a GearWidget and a Rubberbandwidget and puts the
latter on top of the former. Contains a routine that checks that the
default visual is in an overlay plane, and returns the transparent
color of that plane.
</ol>
<p> <h2> Running the Example
</h2>
<a name="1"></a><p> Start the <tt>overlayrubber</tt> executable. Click and drag with the left
mouse button to see rubberband drawing. Observe that the <a href="qglwidget.html">QGLWidget</a>
does not redraw itself (no redraw debug messages are output), and yet
the image is not destroyed. Marvel at the coolness of X11 overlays!
<p> <h2> Using this technique in a real application
</h2>
<a name="2"></a><p> For clarity, this example program has been kept very simple. Here are
some hints for real application usage:
<p> <ul>
<p> <li> <em>All normal widgets are in the overlay plane.</em> This means that you
can put all kinds of Qt widgets (your own or standard Qt widgets) on
top of the OpenGL image (widget), e.g. pushbuttons etc., and they can
be moved, resized, or removed without destroying the OpenGL image.
<p> <li> <em>Using with geometry management.</em> The <a href="qlayout.html">QLayout</a> classes don't permit
putting one widget (the overlay) on top of another (the OpenGL
widget); that would defy the whole purpose of the automatic layout.
The solution is to add just one of them to the QLayout object. Have it
keep a pointer to the other (i.e. the <a href="qglwidget.html">QGLWidget</a> knows about its
overlay widget or vice versa). Implement the resizeEvent() method of
the widget you put in the layout, and make it call setGeometry() on
the other widget with its own geometry as parameters, thus keeping the
two widgets' geometries synchronized.
<p> <li> <em>Using together with <a href="qpalette.html">QPalette</a> and <a href="qcolorgroup.html">QColorGroup</a>.</em> Instead of the
simplistic setBackgroundColor( transparentColor ), you can
use Qt's QPalette system to make your overlay widgets use
transparent color for what you want. This way, the normal Qt widgets
can be used as overlays for fancy effects. Just create a palette for
them with the transparent color for the relevant color roles, e.g.
Background and Base, in the Normal and/or Active modes. This way, you
can create see-through QPushButtons etc.
</ul>
<p> <p>See also <a href="opengl-examples.html">OpenGL Examples</a>.

<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>