Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.gui
Class QLayout

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.core.QObject
                  com.trolltech.qt.gui.QLayout

All Implemented Interfaces:
  QLayoutItemInterface, QtJambiInterface

Direct Known Subclasses:
  QBoxLayout, QFormLayout, QGridLayout, QStackedLayout

    public abstract class QLayout

extends QObject
implements QLayoutItemInterface

The `QLayout` class is the base class of geometry managers. This is an abstract base class inherited by the concrete classes `QBoxLayout`, `QGridLayout`, `QFormLayout`, and `QStackedLayout`.

For users of `QLayout` subclasses or of `QMainWindow` there is seldom any need to use the basic functions provided by `QLayout`, such as `setSizeConstraint()` or `setMenuBar()`. See Layout Classes for more information.

To make your own layout manager, implement the functions `addItem()`, `sizeHint()`, `setGeometry()`, `itemAt()` and `takeAt()`. You should also implement `minimumSize()` to ensure your layout isn't resized to zero size if there is too little space. To support children whose heights depend on their widths, implement `hasHeightForWidth()` and `heightForWidth()`. See the Border Layout and Flow Layout examples for more information about implementing custom layout managers.

Geometry management stops when the layout manager is deleted.

See also:
  `QLayoutItem`, Layout Classes, Basic Layouts Example, Border Layout Example, and Flow Layout Example.

Nested Class Summary
`static class` | `QLayout.SizeConstraint` The possible values are.

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Constructor Summary
`QLayout()` Constructs a new child `QLayout`.
`QLayout(QWidget parent)` Constructs a new top-level `QLayout`, with parent `parent`.

Method Summary
`boolean` | `activate()` Redoes the layout for `parentWidget()` if necessary.
`protected void` | `addChildLayout(QLayout l)` This function is called from `addLayout()` or `insertLayout()` functions in subclasses to add layout `l` as a sub-layout.
`protected void` | `addChildWidget(QWidget w)` This function is called from `addWidget()` functions in subclasses to add `w` as a child widget.
`abstract void` | `addItem(QLayoutItemInterface arg__1)` Implemented in subclasses to add an `item`.
`void` | `addWidget(QWidget w)` Adds widget `w` to this layout in a manner specific to the layout.
`Qt.Alignment` | `alignment()` Returns the alignment of this item.
`protected QRect` | `alignmentRect(QRect arg__1)` Returns the rectangle that should be covered when the geometry of this layout is set to `r`, provided that this layout supports `setAlignment()`.
`static QSize` | `closestAcceptableSize(QWidget w, QSize s)` Returns a size that satisfies all size constraints on `widget`, including `heightForWidth()` and that is as close as possible to `size`.
`QRect` | `contentsRect()` Returns the layout's `geometry()` rectangle, but taking into account the contents margins.
`QSizePolicy.ControlTypes` | `controlTypes()` Returns the control type(s) for the layout item.
`abstract int` | `count()` Must be implemented in subclasses to return the number of items in the layout.
`Qt.Orientations` | `expandingDirections()` Returns whether this layout item can make use of more space than `sizeHint()`.
`static QLayout` | `fromNativePointer(QNativePointer nativePointer)` This method returns the QLayout instance pointed to by `nativePointer`.
`QRect` | `geometry()` Returns the rectangle covered by this layout item.
`QContentsMargins` | `getContentsMargins()` Returns the contents margins of this QLayout.
`boolean` | `hasHeightForWidth()` Returns true if this layout's preferred height depends on its width; otherwise returns false.
`int` | `heightForWidth(int arg__1)` Returns the preferred height for this layout item, given the width `w`.
`int` | `indexOf(QWidget arg__1)` Searches for widget `widget` in this layout (not including child layouts).
`void` | `invalidate()` Invalidates any cached information in this layout item.
`boolean` | `isEmpty()` Implemented in subclasses to return whether this item is empty, i.e.
`boolean` | `isEnabled()` Returns true if the layout is enabled; otherwise returns false.
`abstract QLayoutItemInterface` | `itemAt(int index)` Must be implemented in subclasses to return the layout item at `index`.
`QLayout` | `layout()` If this item is a `QLayout`, it is returned as a `QLayout`; otherwise 0 is returned.
`QSize` | `maximumSize()` Implemented in subclasses to return the maximum size of this item.
`QWidget` | `menuBar()` Returns the menu bar set for this layout, or 0 if no menu bar is set.
`int` | `minimumHeightForWidth(int arg__1)` Returns the minimum height this widget needs for the given width, `w`.
`QSize` | `minimumSize()` Implemented in subclasses to return the minimum size of this item.
`QWidget` | `parentWidget()` Returns the parent widget of this layout, or 0 if this layout is not installed on any widget.
`void` | `removeItem(QLayoutItemInterface arg__1)` Removes the layout item `item` from the layout.
`void` | `removeWidget(QWidget w)` Removes the widget `widget` from the layout.
`boolean` | `setAlignment(QLayout l, Qt.Alignment alignment)` Sets the alignment for the layout `l` to `alignment` and returns true if `l` is found in this layout (not including child layouts); otherwise returns false.
`boolean` | `setAlignment(QLayout l, Qt.AlignmentFlag[] alignment)` Sets the alignment for the layout `l` to `alignment` and returns true if `l` is found in this layout (not including child layouts); otherwise returns false.
`void` | `setAlignment(Qt.Alignment alignment)` Sets the alignment of this item to `alignment`.
`boolean` | `setAlignment(QWidget w, Qt.Alignment alignment)` Sets the alignment for widget `w` to `alignment` and returns true if `w` is found in this layout (not including child layouts); otherwise returns false.
`boolean` | `setAlignment(QWidget w, Qt.AlignmentFlag[] alignment)` Sets the alignment for widget `w` to `alignment` and returns true if `w` is found in this layout (not including child layouts); otherwise returns false.
`void` | `setContentsMargins(int left, int top, int right, int bottom)` Sets the `left`, `top`, `right`, and `bottom` margins to use around the layout.
`void` | `setContentsMargins(QContentsMargins margins)` Sets the contents margins of this QLayout to `margins`.
`void` | `setEnabled(boolean arg__1)` Enables this layout if `enable` is true, otherwise disables it.
`void` | `setGeometry(QRect arg__1)` Implemented in subclasses to set this item's geometry to `r`.
`void` | `setMargin(int arg__1)` This property holds the width of the outside border of the layout.
`void` | `setMenuBar(QWidget w)` Tells the geometry manager to place the menu bar `widget` at the top of `parentWidget()`, outside `QWidget::contentsMargins()`.
`void` | `setSizeConstraint(QLayout.SizeConstraint arg__1)` This property holds the resize mode of the layout.
`void` | `setWidgetSpacing(int arg__1)` This property holds the spacing between widgets inside the layout.
`QLayout.SizeConstraint` | `sizeConstraint()` This property holds the resize mode of the layout.
`abstract QSize` | `sizeHint()` Implemented in subclasses to return the preferred size of this item.
`QSpacerItem` | `spacerItem()` If this item is a `QSpacerItem`, it is returned as a `QSpacerItem`; otherwise 0 is returned.
`abstract QLayoutItemInterface` | `takeAt(int index)` Must be implemented in subclasses to remove the layout item at `index` from the layout, and return the item.
`void` | `update()` Updates the layout for `parentWidget()`.
`QWidget` | `widget()` If this item is a `QWidget`, it is returned as a `QWidget`; otherwise 0 is returned.
`int` | `widgetSpacing()` This property holds the spacing between widgets inside the layout.

Methods inherited from class com.trolltech.qt.core.QObject
`childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Constructor Detail

### QLayout

    public QLayout()

  Constructs a new child `QLayout`.

  This layout has to be inserted into another layout before geometry management will work.

### QLayout

    public QLayout(QWidget parent)

  Constructs a new top-level `QLayout`, with parent `parent`. `parent` may not be 0.

  There can be only one top-level layout for a widget. It is returned by `QWidget::layout()`.

Method Detail

### activate

    public final boolean activate()

  Redoes the layout for `parentWidget()` if necessary.

  You should generally not need to call this because it is automatically called at the most appropriate times. It returns true if the layout was redone.

See also:
  `update()`, and `QWidget::updateGeometry()`.

### addChildLayout

    protected final void addChildLayout(QLayout l)

  This function is called from `addLayout()` or `insertLayout()` functions in subclasses to add layout `l` as a sub-layout.

  The only scenario in which you need to call it directly is if you implement a custom layout that supports nested layouts.

See also:
  `QBoxLayout::addLayout()`, `QBoxLayout::insertLayout()`, and `QGridLayout::addLayout()`.

### addChildWidget

    protected final void addChildWidget(QWidget w)

  This function is called from `addWidget()` functions in subclasses to add `w` as a child widget.

  If `w` is already in a layout, this function will give a warning and remove `w` from the layout. This function must therefore be called before adding `w` to the layout's data structure.

### addWidget

    public final void addWidget(QWidget w)

  Adds widget `w` to this layout in a manner specific to the layout. This function uses `addItem()`.

### alignment

    public final Qt.Alignment alignment()

  Returns the alignment of this item.

See also:
  `setAlignment()`.

  Specified by:
    `alignment` in interface `QLayoutItemInterface`

### alignmentRect

    protected final QRect alignmentRect(QRect arg__1)

  Returns the rectangle that should be covered when the geometry of this layout is set to `r`, provided that this layout supports `setAlignment()`.

  The result is derived from `sizeHint()` and `expanding()`. It is never larger than `r`.

### contentsRect

    public final QRect contentsRect()

  Returns the layout's `geometry()` rectangle, but taking into account the contents margins.

See also:
  `setContentsMargins()`, and `getContentsMargins()`.

### controlTypes

    public final QSizePolicy.ControlTypes controlTypes()

  Returns the control type(s) for the layout item. For a `QWidgetItem`, the control type comes from the widget's size policy; for a `QLayoutItem`, the control types is derived from the layout's contents.

See also:
  `QSizePolicy::controlType()`.

  Specified by:
    `controlTypes` in interface `QLayoutItemInterface`

### isEnabled

    public final boolean isEnabled()

  Returns true if the layout is enabled; otherwise returns false.

See also:
  `setEnabled()`.

### menuBar

    public final QWidget menuBar()

  Returns the menu bar set for this layout, or 0 if no menu bar is set.

See also:
  `setMenuBar()`.

### parentWidget

    public final QWidget parentWidget()

  Returns the parent widget of this layout, or 0 if this layout is not installed on any widget.

  If the layout is a sub-layout, this function returns the parent widget of the parent layout.

See also:
  `parent()`.

### removeItem

    public final void removeItem(QLayoutItemInterface arg__1)

  Removes the layout item `item` from the layout. It is the caller's responsibility to delete the item.

  Notice that `item` can be a layout (since `QLayout` inherits `QLayoutItem`).

See also:
  `removeWidget()`, and `addItem()`.

### removeWidget

    public final void removeWidget(QWidget w)

  Removes the widget `widget` from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout.

  Note: The ownership of `widget` remains the same as when it was added.

See also:
  `removeItem()`, `QWidget::setGeometry()`, and `addWidget()`.

### setAlignment

    public final void setAlignment(Qt.Alignment alignment)

  Sets the alignment of this item to `alignment`.

  Note: Item alignment is only supported by `QLayoutItem` subclasses where it would have a visual effect. Except for `QSpacerItem`, which provides blank space for layouts, all public Qt classes that inherit `QLayoutItem` support item alignment.

See also:
  `alignment()`.

  Specified by:
    `setAlignment` in interface `QLayoutItemInterface`

### setAlignment

    public final boolean setAlignment(QLayout l,
                                      Qt.AlignmentFlag[] alignment)

  Sets the alignment for the layout `l` to `alignment` and returns true if `l` is found in this layout (not including child layouts); otherwise returns false.

### setAlignment

    public final boolean setAlignment(QLayout l,
                                      Qt.Alignment alignment)

  Sets the alignment for the layout `l` to `alignment` and returns true if `l` is found in this layout (not including child layouts); otherwise returns false.

### setAlignment

    public final boolean setAlignment(QWidget w,
                                      Qt.AlignmentFlag[] alignment)

  Sets the alignment for widget `w` to `alignment` and returns true if `w` is found in this layout (not including child layouts); otherwise returns false.

### setAlignment

    public final boolean setAlignment(QWidget w,
                                      Qt.Alignment alignment)

  Sets the alignment for widget `w` to `alignment` and returns true if `w` is found in this layout (not including child layouts); otherwise returns false.

### setContentsMargins

    public final void setContentsMargins(int left,
                                         int top,
                                         int right,
                                         int bottom)

  Sets the `left`, `top`, `right`, and `bottom` margins to use around the layout.

  By default, `QLayout` uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also:
  `getContentsMargins()`, `QStyle::pixelMetric()`, `PM_LayoutLeftMargin` , `PM_LayoutTopMargin` , `PM_LayoutRightMargin` , and `PM_LayoutBottomMargin` .

### setEnabled

    public final void setEnabled(boolean arg__1)

  Enables this layout if `enable` is true, otherwise disables it.

  An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.

  By default all layouts are enabled.

See also:
  `isEnabled()`.

### setMargin

    public final void setMargin(int arg__1)

  This property holds the width of the outside border of the layout. Use `setContentsMargins()` and `getContentsMargins()` instead.

See also:
  `contentsRect()`, and spacing.

### setMenuBar

    public final void setMenuBar(QWidget w)

  Tells the geometry manager to place the menu bar `widget` at the top of `parentWidget()`, outside `QWidget::contentsMargins()`. All child widgets are placed below the bottom edge of the menu bar.

See also:
  `menuBar()`.

### setSizeConstraint

    public final void setSizeConstraint(QLayout.SizeConstraint arg__1)

  This property holds the resize mode of the layout. The default mode is `SetDefaultConstraint` .

### setWidgetSpacing

    public final void setWidgetSpacing(int arg__1)

  This property holds the spacing between widgets inside the layout. If no value is explicitly set, the layout's spacing is inherited from the parent layout, or from the style settings for the parent widget.

  For `QGridLayout` and `QFormLayout`, it is possible to set different horizontal and vertical spacings using `setHorizontalSpacing()` and `setVerticalSpacing()`. In that case, spacing() returns -1.

See also:
  `contentsRect()`, `getContentsMargins()`, `QStyle::layoutSpacing()`, and `QStyle::pixelMetric()`.

### sizeConstraint

    public final QLayout.SizeConstraint sizeConstraint()

  This property holds the resize mode of the layout. The default mode is `SetDefaultConstraint` .

### widgetSpacing

    public final int widgetSpacing()

  This property holds the spacing between widgets inside the layout. If no value is explicitly set, the layout's spacing is inherited from the parent layout, or from the style settings for the parent widget.

  For `QGridLayout` and `QFormLayout`, it is possible to set different horizontal and vertical spacings using `setHorizontalSpacing()` and `setVerticalSpacing()`. In that case, spacing() returns -1.

See also:
  `contentsRect()`, `getContentsMargins()`, `QStyle::layoutSpacing()`, and `QStyle::pixelMetric()`.

### update

    public final void update()

  Updates the layout for `parentWidget()`.

  You should generally not need to call this because it is automatically called at the most appropriate times.

See also:
  `activate()`, and `invalidate()`.

### addItem

    public abstract void addItem(QLayoutItemInterface arg__1)

  Implemented in subclasses to add an `item`. How it is added is specific to each subclass.

  This function is not usually called in application code. To add a widget to a layout, use the `addWidget()` function; to add a child layout, use the `addLayout()` function provided by the relevant `QLayout` subclass.

  Note: The ownership of `item` is transferred to the layout, and it's the layout's responsibility to delete it.

See also:
  `addWidget()`, `QBoxLayout::addLayout()`, and `QGridLayout::addLayout()`.

### count

    public abstract int count()

  Must be implemented in subclasses to return the number of items in the layout.

See also:
  `itemAt()`.

### expandingDirections

    public Qt.Orientations expandingDirections()

  Returns whether this layout item can make use of more space than `sizeHint()`. A value of `Qt::Vertical` or `Qt::Horizontal` means that it wants to grow in only one dimension, whereas `Qt::Vertical` | `Qt::Horizontal` means that it wants to grow in both dimensions.

  Specified by:
    `expandingDirections` in interface `QLayoutItemInterface`

### geometry

    public QRect geometry()

  Returns the rectangle covered by this layout item.

See also:
  `setGeometry()`.

  Specified by:
    `geometry` in interface `QLayoutItemInterface`

### hasHeightForWidth

    public boolean hasHeightForWidth()

  Returns true if this layout's preferred height depends on its width; otherwise returns false. The default implementation returns false.

  Reimplement this function in layout managers that support height for width.

See also:
  `heightForWidth()`, and `QWidget::heightForWidth()`.

  Specified by:
    `hasHeightForWidth` in interface `QLayoutItemInterface`

### heightForWidth

    public int heightForWidth(int arg__1)

  Returns the preferred height for this layout item, given the width `w`.

  The default implementation returns -1, indicating that the preferred height is independent of the width of the item. Using the function `hasHeightForWidth()` will typically be much faster than calling this function and testing for -1.

  Reimplement this function in layout managers that support height for width. A typical implementation will look like this:

          public int heightForWidth(int w)
          {
              if (cache_dirty || cached_width != w) {
                  int h = calculateHeightForWidth(w);
                  cached_hfw = h;
                  return h;
              }
              return cached_hfw;
          }

  Caching is strongly recommended; without it layout will take exponential time.

See also:
  `hasHeightForWidth()`.

  Specified by:
    `heightForWidth` in interface `QLayoutItemInterface`

### indexOf

    public int indexOf(QWidget arg__1)

  Searches for widget `widget` in this layout (not including child layouts).

  Returns the index of `widget`, or -1 if `widget` is not found.

  The default implementation iterates over all items using `itemAt()`

### invalidate

    public void invalidate()

  Invalidates any cached information in this layout item.

  Specified by:
    `invalidate` in interface `QLayoutItemInterface`

### isEmpty

    public boolean isEmpty()

  Implemented in subclasses to return whether this item is empty, i.e. whether it contains any widgets.

  Specified by:
    `isEmpty` in interface `QLayoutItemInterface`

### itemAt

    public abstract QLayoutItemInterface itemAt(int index)

  Must be implemented in subclasses to return the layout item at `index`. If there is no such item, the function must return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

  This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.

              static void paintLayout(QPainter painter, QLayoutItemInterface item)
              {
                  QLayout layout = item.layout();
                  if (layout!=null) {
                      for (int i = 0; i < layout.count(); ++i)
                          paintLayout(painter, layout.itemAt(i));
                  }
                  painter.drawRect(layout.geometry());
              }

              protected void paintEvent(QPaintEvent event)
              {
                  QPainter painter = new QPainter(this);
                  if (layout() != null)
                      paintLayout(painter, layout());
              }

See also:
  `count()`, and `takeAt()`.

### layout

    public QLayout layout()

  If this item is a `QLayout`, it is returned as a `QLayout`; otherwise 0 is returned. This function provides type-safe casting.

  Specified by:
    `layout` in interface `QLayoutItemInterface`

### maximumSize

    public QSize maximumSize()

  Implemented in subclasses to return the maximum size of this item.

  Specified by:
    `maximumSize` in interface `QLayoutItemInterface`

### minimumHeightForWidth

    public int minimumHeightForWidth(int arg__1)

  Returns the minimum height this widget needs for the given width, `w`. The default implementation simply returns `heightForWidth`(`w`).

  Specified by:
    `minimumHeightForWidth` in interface `QLayoutItemInterface`

### minimumSize

    public QSize minimumSize()

  Implemented in subclasses to return the minimum size of this item.

  Specified by:
    `minimumSize` in interface `QLayoutItemInterface`

### setGeometry

    public void setGeometry(QRect arg__1)

  Implemented in subclasses to set this item's geometry to `r`.

See also:
  `geometry()`.

  Specified by:
    `setGeometry` in interface `QLayoutItemInterface`

### sizeHint

    public abstract QSize sizeHint()

  Implemented in subclasses to return the preferred size of this item.

  Specified by:
    `sizeHint` in interface `QLayoutItemInterface`

### spacerItem

    public QSpacerItem spacerItem()

  If this item is a `QSpacerItem`, it is returned as a `QSpacerItem`; otherwise 0 is returned. This function provides type-safe casting.

  Specified by:
    `spacerItem` in interface `QLayoutItemInterface`

### takeAt

    public abstract QLayoutItemInterface takeAt(int index)

  Must be implemented in subclasses to remove the layout item at `index` from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

  The following code fragment shows a safe way to remove all items from a layout:

              QLayoutItemInterface child = null;
              while ((child = layout.takeAt(0)) != null) {
                  //...
                  //delete child;
              }

See also:
  `itemAt()`, and `count()`.

### widget

    public QWidget widget()

  If this item is a `QWidget`, it is returned as a `QWidget`; otherwise 0 is returned. This function provides type-safe casting.

  Specified by:
    `widget` in interface `QLayoutItemInterface`

### closestAcceptableSize

    public static QSize closestAcceptableSize(QWidget w,
                                              QSize s)

  Returns a size that satisfies all size constraints on `widget`, including `heightForWidth()` and that is as close as possible to `size`.

### fromNativePointer

    public static QLayout fromNativePointer(QNativePointer nativePointer)

  This method returns the QLayout instance pointed to by `nativePointer`.

### getContentsMargins

    public final QContentsMargins getContentsMargins()

  Returns the contents margins of this QLayout.

### setContentsMargins

    public final void setContentsMargins(QContentsMargins margins)

  Sets the contents margins of this QLayout to `margins`.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD