Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 2710

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- layout.qdoc -->
<head>
  <title>Qt 4.6: Layout Management</title>
  <link rel="prev" href="widget-classes.html" />
  <link rel="contents" href="widgets-and-layouts.html" />
  <link rel="next" href="style-reference.html" />
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><p>
[Previous: <a href="widget-classes.html">Widget Classes</a>]
[<a href="widgets-and-layouts.html">Widgets and Layouts</a>]
[Next: <a href="style-reference.html">Styles</a>]
</p>
<h1 class="title">Layout Management<br /><span class="subtitle"></span>
</h1>
<p>The Qt layout system provides a simple and powerful way of automatically arranging child widgets within a widget to ensure that they make good use of the available space.</p>
<ul><li><a href="#introduction">Introduction</a></li>
<li><a href="#qt-s-layout-classes">Qt's Layout Classes</a></li>
<li><a href="#horizontal-vertical-grid-and-form-layouts">Horizontal, Vertical, Grid, and Form Layouts</a></li>
<ul><li><a href="#laying-out-widgets-in-code">Laying Out Widgets in Code</a></li>
<li><a href="#tips-for-using-layouts">Tips for Using Layouts</a></li>
</ul>
<li><a href="#adding-widgets-to-a-layout">Adding Widgets to a Layout</a></li>
<ul><li><a href="#stretch-factors">Stretch Factors</a></li>
</ul>
<li><a href="#custom-widgets-in-layouts">Custom Widgets in Layouts</a></li>
<li><a href="#layout-issues">Layout Issues</a></li>
<li><a href="#manual-layout">Manual Layout</a></li>
<li><a href="#how-to-write-a-custom-layout-manager">How to Write A Custom Layout Manager</a></li>
<ul><li><a href="#the-header-file">The Header File (<tt>card.h</tt>)</a></li>
<li><a href="#the-implementation-file">The Implementation File (<tt>card.cpp</tt>)</a></li>
<li><a href="#further-notes">Further Notes</a></li>
</ul>
</ul>
<a name="introduction"></a>
<h3>Introduction</h3>
<p>Qt includes a set of layout management classes that are used to describe how widgets are laid out in an application's user interface. These layouts automatically position and resize widgets when the amount of space available for them changes, ensuring that they are consistently arranged and that the user interface as a whole remains usable.</p>
<p>All <a href="qwidget.html">QWidget</a> subclasses can use layouts to manage their children. The <a href="qwidget.html#setLayout">QWidget::setLayout</a>() function applies a layout to a widget. When a layout is set on a widget in this way, it takes charge of the following tasks:</p>
<ul>
<li>Positioning of child widgets.</li>
<li>Sensible default sizes for windows.</li>
<li>Sensible minimum sizes for windows.</li>
<li>Resize handling.</li>
<li>Automatic updates when contents change:<ul>
<li>Font size, text or other contents of child widgets.</li>
<li>Hiding or showing a child widget.</li>
<li>Removal of child widgets.</li>
</ul>
</li>
</ul>
<a name="qt-s-layout-classes"></a>
<h3>Qt's Layout Classes</h3>
<p>Qt's layout classes were designed for hand-written C++ code, allowing measurements to be specified in pixels for simplicity, so they are easy to understand and use. The code generated for forms created using <i>Qt Designer</i> also uses the layout classes. <i>Qt Designer</i> is useful to use when experimenting with the design of a form since it avoids the compile, link and run cycle usually involved in user interface development.</p>
<p><table width="100%" class="annotated" cellpadding="2" cellspacing="1" border="0">
<tr valign="top" class="odd"><th><a href="qboxlayout.html">QBoxLayout</a></th><td>Lines up child widgets horizontally or vertically</td></tr>
<tr valign="top" class="even"><th><a href="qbuttongroup.html">QButtonGroup</a></th><td>Container to organize groups of button widgets</td></tr>
<tr valign="top" class="odd"><th><a href="qformlayout.html">QFormLayout</a></th><td>Manages forms of input widgets and their associated labels</td></tr>
<tr valign="top" class="even"><th><a href="qgraphicsanchor.html">QGraphicsAnchor</a></th><td>Represents an anchor between two items in a QGraphicsAnchorLayout</td></tr>
<tr valign="top" class="odd"><th><a href="qgraphicsanchorlayout.html">QGraphicsAnchorLayout</a></th><td>Layout where one can anchor widgets together in Graphics View</td></tr>
<tr valign="top" class="even"><th><a href="qgridlayout.html">QGridLayout</a></th><td>Lays out widgets in a grid</td></tr>
<tr valign="top" class="odd"><th><a href="qgroupbox.html">QGroupBox</a></th><td>Group box frame with a title</td></tr>
<tr valign="top" class="even"><th><a href="qhboxlayout.html">QHBoxLayout</a></th><td>Lines up widgets horizontally</td></tr>
<tr valign="top" class="odd"><th><a href="qlayout.html">QLayout</a></th><td>The base class of geometry managers</td></tr>
<tr valign="top" class="even"><th><a href="qlayoutitem.html">QLayoutItem</a></th><td>Abstract item that a QLayout manipulates</td></tr>
<tr valign="top" class="odd"><th><a href="qsizepolicy.html">QSizePolicy</a></th><td>Layout attribute describing horizontal and vertical resizing policy</td></tr>
<tr valign="top" class="even"><th><a href="qspaceritem.html">QSpacerItem</a></th><td>Blank space in a layout</td></tr>
<tr valign="top" class="odd"><th><a href="qstackedlayout.html">QStackedLayout</a></th><td>Stack of widgets where only one widget is visible at a time</td></tr>
<tr valign="top" class="even"><th><a href="qstackedwidget.html">QStackedWidget</a></th><td>Stack of widgets where only one widget is visible at a time</td></tr>
<tr valign="top" class="odd"><th><a href="qvboxlayout.html">QVBoxLayout</a></th><td>Lines up widgets vertically</td></tr>
<tr valign="top" class="even"><th><a href="qwidgetitem.html">QWidgetItem</a></th><td>Layout item that represents a widget</td></tr>
</table></p>
<a name="horizontal-vertical-grid-and-form-layouts"></a>
<h3>Horizontal, Vertical, Grid, and Form Layouts</h3>
<p>The easiest way to give your widgets a good layout is to use the built-in layout managers: <a href="qhboxlayout.html">QHBoxLayout</a>, <a href="qvboxlayout.html">QVBoxLayout</a>, <a href="qgridlayout.html">QGridLayout</a>, and <a href="qformlayout.html">QFormLayout</a>. These classes inherit from <a href="qlayout.html">QLayout</a>, which in turn derives from <a href="qobject.html">QObject</a> (not <a href="qwidget.html">QWidget</a>). They take care of geometry management for a set of widgets. To create more complex layouts, you can nest layout managers inside each other.</p>
<ul>
<li>A <a href="qhboxlayout.html">QHBoxLayout</a> lays out widgets in a horizontal row, from left to right (or right to left for right-to-left languages).<p align="center"><img src="images/qhboxlayout-with-5-children.png" /></p></li>
<li>A <a href="qvboxlayout.html">QVBoxLayout</a> lays out widgets in a vertical column, from top to bottom.<p align="center"><img src="images/qvboxlayout-with-5-children.png" /></p></li>
<li>A <a href="qgridlayout.html">QGridLayout</a> lays out widgets in a two-dimensional grid. Widgets can occupy multiple cells.<p align="center"><img src="images/qgridlayout-with-5-children.png" /></p></li>
<li>A <a href="qformlayout.html">QFormLayout</a> lays out widgets in a 2-column descriptive label- field style.<p align="center"><img src="images/qformlayout-with-6-children.png" /></p></li>
</ul>
<a name="laying-out-widgets-in-code"></a>
<h4>Laying Out Widgets in Code</h4>
<p>The following code creates a <a href="qhboxlayout.html">QHBoxLayout</a> that manages the geometry of five <a href="qpushbutton.html">QPushButton</a>s, as shown on the first screenshot above:</p>
<pre>     QWidget *window = new QWidget;
     QPushButton *button1 = new QPushButton(&quot;One&quot;);
     QPushButton *button2 = new QPushButton(&quot;Two&quot;);
     QPushButton *button3 = new QPushButton(&quot;Three&quot;);
     QPushButton *button4 = new QPushButton(&quot;Four&quot;);
     QPushButton *button5 = new QPushButton(&quot;Five&quot;);

     QHBoxLayout *layout = new QHBoxLayout;
     layout-&gt;addWidget(button1);
     layout-&gt;addWidget(button2);
     layout-&gt;addWidget(button3);
     layout-&gt;addWidget(button4);
     layout-&gt;addWidget(button5);

     window-&gt;setLayout(layout);
     window-&gt;show();</pre>
<p>The code for <a href="qvboxlayout.html">QVBoxLayout</a> is identical, except the line where the layout is created. The code for <a href="qgridlayout.html">QGridLayout</a> is a bit different, because we need to specify the row and column position of the child widget:</p>
<pre>     QWidget *window = new QWidget;
     QPushButton *button1 = new QPushButton(&quot;One&quot;);
     QPushButton *button2 = new QPushButton(&quot;Two&quot;);
     QPushButton *button3 = new QPushButton(&quot;Three&quot;);
     QPushButton *button4 = new QPushButton(&quot;Four&quot;);
     QPushButton *button5 = new QPushButton(&quot;Five&quot;);

     QGridLayout *layout = new QGridLayout;
     layout-&gt;addWidget(button1, 0, 0);
     layout-&gt;addWidget(button2, 0, 1);
     layout-&gt;addWidget(button3, 1, 0, 1, 2);
     layout-&gt;addWidget(button4, 2, 0);
     layout-&gt;addWidget(button5, 2, 1);

     window-&gt;setLayout(layout);
     window-&gt;show();</pre>
<p>The third <a href="qpushbutton.html">QPushButton</a> spans 2 columns. This is possible by specifying 2 as the fifth argument to <a href="qgridlayout.html#addWidget">QGridLayout::addWidget</a>().</p>
<p>Finally, the code for <a href="qformlayout.html">QFormLayout</a> is ..</p>
<a name="tips-for-using-layouts"></a>
<h4>Tips for Using Layouts</h4>
<p>When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using <a href="qwidget.html#setParent">QWidget::setParent</a>()) so that they are children of the widget on which the layout is installed.</p>
<p><b>Note:</b> Widgets in a layout are children of the widget on which the layout is installed, <i>not</i> of the layout itself. Widgets can only have other widgets as parent, not layouts.</p>
<p>You can nest layouts using <tt>addLayout()</tt> on a layout; the inner layout then becomes a child of the layout it is inserted into.</p>
<a name="adding-widgets-to-a-layout"></a>
<h3>Adding Widgets to a Layout</h3>
<p>When you add widgets to a layout, the layout process works as follows:</p>
<ol type="1">
<li>All the widgets will initially be allocated an amount of space in accordance with their <a href="qwidget.html#sizePolicy-prop">QWidget::sizePolicy</a>() and <a href="qwidget.html#sizeHint-prop">QWidget::sizeHint</a>().</li>
<li>If any of the widgets have stretch factors set, with a value greater than zero, then they are allocated space in proportion to their stretch factor (explained below).</li>
<li>If any of the widgets have stretch factors set to zero they will only get more space if no other widgets want the space. Of these, space is allocated to widgets with an <a href="qsizepolicy.html#Policy-enum">Expanding</a> size policy first.</li>
<li>Any widgets that are allocated less space than their minimum size (or minimum size hint if no minimum size is specified) are allocated this minimum size they require. (Widgets don't have to have a minimum size or minimum size hint in which case the strech factor is their determining factor.)</li>
<li>Any widgets that are allocated more space than their maximum size are allocated the maximum size space they require. (Widgets do not have to have a maximum size in which case the strech factor is their determining factor.)</li>
</ol>
<a name="stretch-factors"></a>
<h4>Stretch Factors</h4>
<a name="stretch-factor"></a><p>Widgets are normally created without any stretch factor set. When they are laid out in a layout the widgets are given a share of space in accordance with their <a href="qwidget.html#sizePolicy-prop">QWidget::sizePolicy</a>() or their minimum size hint whichever is the greater. Stretch factors are used to change how much space widgets are given in proportion to one another.</p>
<p>If we have three widgets laid out using a <a href="qhboxlayout.html">QHBoxLayout</a> with no stretch factors set we will get a layout like this:</p>
<p align="center"><img src="images/layout1.png" alt="Three widgets in a row" /></p><p>If we apply stretch factors to each widget, they will be laid out in proportion (but never less than their minimum size hint), e.g&#x2e;</p>
<p align="center"><img src="images/layout2.png" alt="Three widgets with different stretch factors in a row" /></p><a name="custom-widgets-in-layouts"></a>
<h3>Custom Widgets in Layouts</h3>
<p>When you make your own widget class, you should also communicate its layout properties. If the widget has a one of Qt's layouts, this is already taken care of. If the widget does not have any child widgets, or uses manual layout, you can change the behavior of the widget using any or all of the following mechanisms:</p>
<ul>
<li>Reimplement <a href="qwidget.html#sizeHint-prop">QWidget::sizeHint</a>() to return the preferred size of the widget.</li>
<li>Reimplement <a href="qwidget.html#minimumSizeHint-prop">QWidget::minimumSizeHint</a>() to return the smallest size the widget can have.</li>
<li>Call <a href="qwidget.html#sizePolicy-prop">QWidget::setSizePolicy</a>() to specify the space requirements of the widget.</li>
</ul>
<p>Call <a href="qwidget.html#updateGeometry">QWidget::updateGeometry</a>() whenever the size hint, minimum size hint or size policy changes. This will cause a layout recalculation. Multiple consecutive calls to <a href="qwidget.html#updateGeometry">QWidget::updateGeometry</a>() will only cause one layout recalculation.</p>
<p>If the preferred height of your widget depends on its actual width (e.g&#x2e;, a label with automatic word-breaking), set the <a href="qsizepolicy.html#hasHeightForWidth">height-for-width</a> flag in the widget's <a href="qwidget.html#sizePolicy-prop">size policy</a> and reimplement <a href="qwidget.html#heightForWidth">QWidget::heightForWidth</a>().</p>
<p>Even if you implement <a href="qwidget.html#heightForWidth">QWidget::heightForWidth</a>(), it is still a good idea to provide a reasonable sizeHint().</p>
<p>For further guidance when implementing these functions, see the <i>Qt Quarterly</i> article <a href="http://qt.nokia.com/doc/qq/qq04-height-for-width.html">Trading Height for Width</a>.</p>
<a name="layout-issues"></a>
<h3>Layout Issues</h3>
<p>The use of rich text in a label widget can introduce some problems to the layout of its parent widget. Problems occur due to the way rich text is handled by Qt's layout managers when the label is word wrapped.</p>
<p>In certain cases the parent layout is put into <a href="qlayout.html#SizeConstraint-enum">QLayout::FreeResize</a> mode, meaning that it will not adapt the layout of its contents to fit inside small sized windows, or even prevent the user from making the window too small to be usable. This can be overcome by subclassing the problematic widgets, and implementing suitable <a href="qwidget.html#sizeHint-prop">sizeHint()</a> and <a href="qwidget.html#minimumSizeHint-prop">minimumSizeHint()</a> functions.</p>
<p>In some cases, it is relevant when a layout is added to a widget. When you set the widget of a <a href="qdockwidget.html">QDockWidget</a> or a <a href="qscrollarea.html">QScrollArea</a> (with <a href="qdockwidget.html#setWidget">QDockWidget::setWidget</a>() and <a href="qscrollarea.html#setWidget">QScrollArea::setWidget</a>()), the layout must already have been set on the widget. If not, the widget will not be visible.</p>
<a name="manual-layout"></a>
<h3>Manual Layout</h3>
<p>If you are making a one-of-a-kind special layout, you can also make a custom widget as described above. Reimplement <a href="qwidget.html#resizeEvent">QWidget::resizeEvent</a>() to calculate the required distribution of sizes and call <a href="qwidget.html#geometry-prop">setGeometry()</a> on each child.</p>
<p>The widget will get an event of type <a href="qevent.html#Type-enum">QEvent::LayoutRequest</a> when the layout needs to be recalculated. Reimplement <a href="qwidget.html#event">QWidget::event</a>() to handle <a href="qevent.html#Type-enum">QEvent::LayoutRequest</a> events.</p>
<a name="how-to-write-a-custom-layout-manager"></a>
<h3>How to Write A Custom Layout Manager</h3>
<p>An alternative to manual layout is to write your own layout manager by subclassing <a href="qlayout.html">QLayout</a>. The <a href="layouts-borderlayout.html">Border Layout</a> and <a href="layouts-flowlayout.html">Flow Layout</a> examples show how to do this.</p>
<p>Here we present an example in detail. The <tt>CardLayout</tt> class is inspired by the Java layout manager of the same name. It lays out the items (widgets or nested layouts) on top of each other, each item offset by <a href="qlayout.html#spacing-prop">QLayout::spacing</a>().</p>
<p>To write your own layout class, you must define the following:</p>
<ul>
<li>A data structure to store the items handled by the layout. Each item is a <a href="qlayoutitem.html">QLayoutItem</a>. We will use a <a href="qlist.html">QList</a> in this example.</li>
<li><a href="qlayout.html#addItem">addItem()</a>, how to add items to the layout.</li>
<li><a href="qlayout.html#setGeometry">setGeometry()</a>, how to perform the layout.</li>
<li><a href="qlayoutitem.html#sizeHint">sizeHint()</a>, the preferred size of the layout.</li>
<li><a href="qlayout.html#itemAt">itemAt()</a>, how to iterate over the layout.</li>
<li><a href="qlayout.html#takeAt">takeAt()</a>, how to remove items from the layout.</li>
</ul>
<p>In most cases, you will also implement <a href="qlayout.html#minimumSize">minimumSize()</a>.</p>
<a name="the-header-file"></a>
<h4>The Header File (<tt>card.h</tt>)</h4>
<pre> #ifndef CARD_H
 #define CARD_H

 #include &lt;QtGui&gt;
 #include &lt;QList&gt;

 class CardLayout : public QLayout
 {
 public:
     CardLayout(QWidget *parent, int dist): QLayout(parent, 0, dist) {}
     CardLayout(QLayout *parent, int dist): QLayout(parent, dist) {}
     CardLayout(int dist): QLayout(dist) {}
     ~CardLayout();

     void addItem(QLayoutItem *item);
     QSize sizeHint() const;
     QSize minimumSize() const;
         QLayoutItem *count() const;
     QLayoutItem *itemAt(int) const;
     QLayoutItem *takeAt(int);
     void setGeometry(const QRect &amp;rect);

 private:
     QList&lt;QLayoutItem*&gt; list;
 };
 #endif</pre>
<a name="the-implementation-file"></a>
<h4>The Implementation File (<tt>card.cpp</tt>)</h4>
<pre> //#include &quot;card.h&quot;</pre>
<p>First we define <tt>count()</tt> to fetch the number of items in the list.</p>
<pre> QLayoutItem *CardLayout::count() const
 {
         // QList::size() returns the number of QLayoutItems in the list
     return list.size();
 }</pre>
<p>Then we define two functions that iterate over the layout: <tt>itemAt()</tt> and <tt>takeAt()</tt>. These functions are used internally by the layout system to handle deletion of widgets. They are also available for application programmers.</p>
<p><tt>itemAt()</tt> returns the item at the given index. <tt>takeAt()</tt> removes the item at the given index, and returns it. In this case we use the list index as the layout index. In other cases where we have a more complex data structure, we may have to spend more effort defining a linear order for the items.</p>
<pre> QLayoutItem *CardLayout::itemAt(int idx) const
 {
     // QList::value() performs index checking, and returns 0 if we are
     // outside the valid range
     return list.value(idx);
 }

 QLayoutItem *CardLayout::takeAt(int idx)
 {
     // QList::take does not do index checking
     return idx &gt;= 0 &amp;&amp; idx &lt; list.size() ? list.takeAt(idx) : 0;
 }</pre>
<p><tt>addItem()</tt> implements the default placement strategy for layout items. This function must be implemented. It is used by <a href="qlayout-qt3.html#add" class="compat">QLayout::add</a>(), by the <a href="qlayout.html">QLayout</a> constructor that takes a layout as parent. If your layout has advanced placement options that require parameters, you must provide extra access functions such as the row and column spanning overloads of <a href="qgridlayout.html#addItem">QGridLayout::addItem</a>(), <a href="qgridlayout.html#addWidget">QGridLayout::addWidget</a>(), and <a href="qgridlayout.html#addLayout">QGridLayout::addLayout</a>().</p>
<pre> void CardLayout::addItem(QLayoutItem *item)
 {
     list.append(item);
 }</pre>
<p>The layout takes over responsibility of the items added. Since <a href="qlayoutitem.html">QLayoutItem</a> does not inherit <a href="qobject.html">QObject</a>, we must delete the items manually. In the destructor, we remove each item from the list using <tt>takeAt()</tt>, and then delete it.</p>
<pre> CardLayout::~CardLayout()
 {
      QLayoutItem *item;
      while ((item = takeAt(0)))
          delete item;
 }</pre>
<p>The <tt>setGeometry()</tt> function actually performs the layout. The rectangle supplied as an argument does not include <tt>margin()</tt>. If relevant, use <tt>spacing()</tt> as the distance between items.</p>
<pre> void CardLayout::setGeometry(const QRect &amp;r)
 {
     QLayout::setGeometry(r);

     if (list.size() == 0)
         return;

     int w = r.width() - (list.count() - 1) * spacing();
     int h = r.height() - (list.count() - 1) * spacing();
     int i = 0;
     while (i &lt; list.size()) {
         QLayoutItem *o = list.at(i);
         QRect geom(r.x() + i * spacing(), r.y() + i * spacing(), w, h);
         o-&gt;setGeometry(geom);
         ++i;
     }
 }</pre>
<p><tt>sizeHint()</tt> and <tt>minimumSize()</tt> are normally very similar in implementation. The sizes returned by both functions should include <tt>spacing()</tt>, but not <tt>margin()</tt>.</p>
<pre> QSize CardLayout::sizeHint() const
 {
     QSize s(0,0);
     int n = list.count();
     if (n &gt; 0)
         s = QSize(100,70); //start with a nice default size
     int i = 0;
     while (i &lt; n) {
         QLayoutItem *o = list.at(i);
         s = s.expandedTo(o-&gt;sizeHint());
         ++i;
     }
     return s + n*QSize(spacing(), spacing());
 }

 QSize CardLayout::minimumSize() const
 {
     QSize s(0,0);
     int n = list.count();
     int i = 0;
     while (i &lt; n) {
         QLayoutItem *o = list.at(i);
         s = s.expandedTo(o-&gt;minimumSize());
         ++i;
     }
     return s + n*QSize(spacing(), spacing());
 }</pre>
<a name="further-notes"></a>
<h4>Further Notes</h4>
<ul>
<li>This custom layout does not handle height for width.</li>
<li>We ignore <a href="qlayoutitem.html#isEmpty">QLayoutItem::isEmpty</a>(); this means that the layout will treat hidden widgets as visible.</li>
<li>For complex layouts, speed can be greatly increased by caching calculated values. In that case, implement <a href="qlayoutitem.html#invalidate">QLayoutItem::invalidate</a>() to mark the cached data is dirty.</li>
<li>Calling <a href="qlayoutitem.html#sizeHint">QLayoutItem::sizeHint</a>(), etc. may be expensive. So, you should store the value in a local variable if you need it again later within in the same function.</li>
<li>You should not call <a href="qlayoutitem.html#setGeometry">QLayoutItem::setGeometry</a>() twice on the same item in the same function. This call can be very expensive if the item has several child widgets, because the layout manager must do a complete layout every time. Instead, calculate the geometry and then set it. (This does not only apply to layouts, you should do the same if you implement your own resizeEvent(), for example.)</li>
</ul>
<p>
[Previous: <a href="widget-classes.html">Widget Classes</a>]
[<a href="widgets-and-layouts.html">Widgets and Layouts</a>]
[Next: <a href="style-reference.html">Styles</a>]
</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>