[190] | 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"><!--
|
---|
| 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>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
|
---|
| 38 | geometry. Some of these functions operate on the pure client area
|
---|
| 39 | (i.e. the window excluding the window frame), others include the
|
---|
| 40 | window frame. The differentiation is done in a way that covers the
|
---|
| 41 | most 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
|
---|
| 51 | widgets. For all child widgets, the frame geometry is equal to the
|
---|
| 52 | widget'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
|
---|
| 58 | decorates it. This happens asynchronously at some point in time after
|
---|
| 59 | calling show() and the first paint event the window receives: or it
|
---|
| 60 | does not happen at all. Bear in mind that X11 is policy-free (others
|
---|
| 61 | call it flexible). Thus you cannot make any safe assumption about the
|
---|
| 62 | decoration frame your window will get. Basic rule: there's always one
|
---|
| 63 | user who uses a window manager that breaks your assumption, and who
|
---|
| 64 | will complain to you.
|
---|
| 65 | <p> Furthermore, a toolkit cannot simply place windows on the screen. All
|
---|
| 66 | Qt can do is to send certain hints to the window manager. The window
|
---|
| 67 | manager, a separate process, may either obey, ignore or misunderstand
|
---|
| 68 | them. Due to the partially unclear Inter-Client Communication
|
---|
| 69 | Conventions Manual (ICCCM), window placement is handled quite
|
---|
| 70 | differently in existing window managers.
|
---|
| 71 | <p> X11 provides no standard or easy way to get the frame geometry once
|
---|
| 72 | the window is decorated. Qt solves this problem with nifty heuristics
|
---|
| 73 | and clever code that works on a wide range of window managers that
|
---|
| 74 | exist today. Don't be surprised if you find one where frameGeometry()
|
---|
| 75 | returns bogus results though.
|
---|
| 76 | <p> Nor does X11 provide a way to maximize a window. The showMaximized()
|
---|
| 77 | function in Qt therefore has to emulate the feature. Its result
|
---|
| 78 | depends on the result of frameGeometry() and the capability of the
|
---|
| 79 | window manager to do proper window placement, neither of which can be
|
---|
| 80 | guaranteed.
|
---|
| 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
|
---|
| 84 | in a later session. On Windows, this is basically storing the result
|
---|
| 85 | of geometry() and calling setGeometry() in the next session before
|
---|
| 86 | calling show(). On X11, this won't work because an invisible window
|
---|
| 87 | doesn't have a frame yet. The window manager would decorate the window
|
---|
| 88 | later. When this happens, the window shifts towards the bottom/right
|
---|
| 89 | corner of the screen depending on the size of the decoration frame. X
|
---|
| 90 | theoretically provides a way to avoid this shift. Our tests have
|
---|
| 91 | shown, though, that almost all window managers fail to implement this
|
---|
| 92 | feature.
|
---|
| 93 | <p> A workaround is to call setGeometry() after show(). This has the
|
---|
| 94 | two disadvantages that the widget appears at a wrong place for a
|
---|
| 95 | millisecond (results in flashing) and that currently only every
|
---|
| 96 | second window manager gets it right. A safer solution is to store
|
---|
| 97 | both pos() and size() and to restore the geometry using resize() and
|
---|
| 98 | move() before calling show(), as demonstrated in the following
|
---|
| 99 | example:
|
---|
| 100 | <p> <pre>
|
---|
| 101 | MyWidget* widget = new MyWidget
|
---|
| 102 | ...
|
---|
| 103 | <a href="qpoint.html">QPoint</a> p = widget->pos(); // store position
|
---|
| 104 | <a href="qsize.html">QSize</a> s = widget->size(); // store size
|
---|
| 105 | ...
|
---|
| 106 | widget = new MyWidget;
|
---|
| 107 | widget->resize( s ); // restore size
|
---|
| 108 | widget->move( p ); // restore position
|
---|
| 109 | widget->show(); // show widget
|
---|
| 110 | </pre>
|
---|
| 111 |
|
---|
| 112 | <p> This method works on both MS-Windows and most existing X11 window
|
---|
| 113 | managers.
|
---|
| 114 | <p>
|
---|
| 115 | <!-- eof -->
|
---|
| 116 | <p><address><hr><div align=center>
|
---|
| 117 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 118 | <td>Copyright © 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>
|
---|