summaryrefslogtreecommitdiffstats
path: root/examples/opengl/overlay_x11/README
blob: eba728e672e1a856969d684fdca97337e76d0f89 (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

-----------------------------------------------------------------------
UPDATE: 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 'overlay'
example program. The following is a discussion on how to use non-QGL
widgets in overlay planes.
-----------------------------------------------------------------------

Overlayrubber: An example program showing how to use Qt and Qt OpenGL
Extension with X11 overlay visuals.

(Background information for this example can be found in the file
 README.X11-OVERLAYS)

The example program has three main parts:

GearWidget: A simple QGLWidget that renders the usual gears. Modified
so that it will print a debug message every time it redraws (renders)
itself. Thus, you can eaily confirm that drawing in the overlay plane
does not cause redrawings in the main plane where the QGLWidget
resides.

RubberbandWidget: Very simple standard (non-GL) Qt widget that
implements rubberband drawing. Designed for use in an overlay
plane. It takes the planes' 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.

main.cpp: 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.


Running it:
-----------

Start the overlayrubber executable. Click and drag with the left mouse
button to see rubberband drawing. Observe that the QGLWidget does
not redraw itself (no redraw debug messages are output), and yet the
image is not destroyed. Marvel at the coolness of X11 overlays!


Using this technique in a real application
------------------------------------------

For clarity, this example program has been kept very simple. Here are
some hints for real application use:

All normal widgets can go in the overlay plane: This means that you
can put all kinds of Qt widgets (your own or those provided with Qt)
on top of the OpenGL image (widget), e.g. pushbuttons etc., and they
can be moved, resized, or removed without destroying the OpenGL image.

Using with geometry management: The QLayout classes will not allow you
to put 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 QGLWidget 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.

Using with QPalette and QColorGroup: Instead of the somewhat
simplistic setBackgroundColor( transparentColor ), you can use Qt's
QPalette system for having 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 wanted color roles, e.g. Background and
Base, in the Normal and/or Active modes. This way, you can create
see-through QPushButtons etc.