source: trunk/doc/html/geometry.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 5.7 KB
Line 
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/doc/misc.doc:1031 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>Window Geometry</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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>Window Geometry</h1>
33
34
35<h2> Overview
36</h2>
37<a name="1"></a><p> <a href="qwidget.html">QWidget</a> provides several functions that deal with a widget's
38geometry. Some of these functions operate on the pure client area
39(i.e. the window excluding the window frame), others include the
40window frame. The differentiation is done in a way that covers the
41most common usage transparently.
42<p> <center><table cellpadding="4" cellspacing="2" border="0">
43<tr bgcolor="#f0f0f0">
44<td valign="top"><strong>Including the window frame:
45<td valign="top">x(), y(), frameGeometry(), pos() and move()
46<tr bgcolor="#d0d0d0">
47<td valign="top"><strong>Excluding the window frame:</strong>
48<td valign="top">geometry(), width(), height(), rect() and size()
49</table></center>
50<p> Note that the distinction only matters for decorated top-level
51widgets. For all child widgets, the frame geometry is equal to the
52widget's client geometry.
53<p> This diagram shows most of the functions in use:
54<center><img src="geometry.png" alt="Geometry diagram"></center>
55<p> <h2> Unix/X11 peculiarities
56</h2>
57<a name="2"></a><p> On Unix/X11, a window does not have a frame until the window manager
58decorates it. This happens asynchronously at some point in time after
59calling show() and the first paint event the window receives: or it
60does not happen at all. Bear in mind that X11 is policy-free (others
61call it flexible). Thus you cannot make any safe assumption about the
62decoration frame your window will get. Basic rule: there's always one
63user who uses a window manager that breaks your assumption, and who
64will complain to you.
65<p> Furthermore, a toolkit cannot simply place windows on the screen. All
66Qt can do is to send certain hints to the window manager. The window
67manager, a separate process, may either obey, ignore or misunderstand
68them. Due to the partially unclear Inter-Client Communication
69Conventions Manual (ICCCM), window placement is handled quite
70differently in existing window managers.
71<p> X11 provides no standard or easy way to get the frame geometry once
72the window is decorated. Qt solves this problem with nifty heuristics
73and clever code that works on a wide range of window managers that
74exist today. Don't be surprised if you find one where frameGeometry()
75returns bogus results though.
76<p> Nor does X11 provide a way to maximize a window. The showMaximized()
77function in Qt therefore has to emulate the feature. Its result
78depends on the result of frameGeometry() and the capability of the
79window manager to do proper window placement, neither of which can be
80guaranteed.
81<p> <h2> Restoring a Window's Geometry
82</h2>
83<a name="3"></a><p> A common task in modern applications is to restore a window's geometry
84in a later session. On Windows, this is basically storing the result
85of geometry() and calling setGeometry() in the next session before
86calling show(). On X11, this won't work because an invisible window
87doesn't have a frame yet. The window manager would decorate the window
88later. When this happens, the window shifts towards the bottom/right
89corner of the screen depending on the size of the decoration frame. X
90theoretically provides a way to avoid this shift. Our tests have
91shown, though, that almost all window managers fail to implement this
92feature.
93<p> A workaround is to call setGeometry() after show(). This has the
94two disadvantages that the widget appears at a wrong place for a
95millisecond (results in flashing) and that currently only every
96second window manager gets it right. A safer solution is to store
97both pos() and size() and to restore the geometry using resize() and
98move() before calling show(), as demonstrated in the following
99example:
100<p> <pre>
101 MyWidget* widget = new MyWidget
102 ...
103 <a href="qpoint.html">QPoint</a> p = widget-&gt;pos(); // store position
104 <a href="qsize.html">QSize</a> s = widget-&gt;size(); // store size
105 ...
106 widget = new MyWidget;
107 widget-&gt;resize( s ); // restore size
108 widget-&gt;move( p ); // restore position
109 widget-&gt;show(); // show widget
110</pre>
111
112<p> This method works on both MS-Windows and most existing X11 window
113managers.
114<p>
115<!-- eof -->
116<p><address><hr><div align=center>
117<table width=100% cellspacing=0 border=0><tr>
118<td>Copyright &copy; 2007
119<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
120<td align=right><div align=right>Qt 3.3.8</div>
121</table></div></address></body>
122</html>
Note: See TracBrowser for help on using the repository browser.