Qt Jambi Home

com.trolltech.qt.gui
Class QLayout

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QLayout
All Implemented Interfaces:
QLayoutItemInterface, QtJambiInterface
Direct Known Subclasses:
QBoxLayout, 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, 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, Layouts Example, Layout Example, Layout Example

Nested Class Summary
static class QLayout.SizeConstraint
          The possible values are.
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
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 arg__1.
 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 arg__1, provided that this layout supports setAlignment.
protected  void childEvent(QChildEvent e)
          This function is reimplemented for internal reasons.
static QSize closestAcceptableSize(QWidget w, QSize s)
          Returns a size that satisfies all size constraints on w, including heightForWidth and that is as close as possible to s.
 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 can make use of more space than sizeHint.
static QLayout fromNativePointer(QNativePointer nativePointer)
          This function returns the QLayout instance pointed to by nativePointer
 QRect geometry()
          This function is reimplemented for internal reasons.
 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 arg__1.
 int indexOf(QWidget arg__1)
          Searches for widget arg__1 in this layout (not including child layouts).
 void invalidate()
          This function is reimplemented for internal reasons.
 boolean isEmpty()
          This function is reimplemented for internal reasons.
 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()
          This function is reimplemented for internal reasons.
 QSize maximumSize()
          Returns the maximum size of this layout.
 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, arg__1.
 QSize minimumSize()
          Returns the minimum size of this layout.
 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 arg__1 from the layout.
 void removeWidget(QWidget w)
          Removes the widget w 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 arg__1 is true, otherwise disables it.
abstract  void setGeometry(QRect arg__1)
          This function is reimplemented for internal reasons.
 void setMargin(int arg__1)
          This method is obsolete.
 void setMenuBar(QWidget w)
          Tells the geometry manager to place the menu bar w at the top of parentWidget, outside QWidget::contentsMargins().
 void setSizeConstraint(QLayout.SizeConstraint arg__1)
          Sets the resize mode of the layout to arg__1.
 void setWidgetSpacing(int arg__1)
          Sets the spacing between widgets inside the layout to arg__1.
 QLayout.SizeConstraint sizeConstraint()
          Returns 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.
 int totalHeightForWidth(int w)
          
 QSize totalMaximumSize()
          
 QSize totalMinimumSize()
          
 QSize totalSizeHint()
          
 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.
protected  void widgetEvent(QEvent arg__1)
          
 int widgetSpacing()
          Returns the spacing between widgets inside the layout.
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

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().


QLayout

public QLayout()

Constructs a new child QLayout.

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

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, 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, 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.

Specified by:
alignment in interface QLayoutItemInterface
See Also:
setAlignment

alignmentRect

protected final QRect alignmentRect(QRect arg__1)

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

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


contentsRect

public final QRect contentsRect()

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

See Also:
setContentsMargins, 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.

Specified by:
controlTypes in interface QLayoutItemInterface
See Also:
QSizePolicy::controlType

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 arg__1 from the layout. It is the caller's responsibility to delete the item.

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

See Also:
removeWidget, addItem

removeWidget

public final void removeWidget(QWidget w)

Removes the widget w 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 w remains the same as when it was added.

See Also:
removeItem, QWidget::setGeometry, addWidget

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.


setAlignment

public final void setAlignment(Qt.Alignment alignment)

Sets the alignment of this item to alignment.

Specified by:
setAlignment in interface QLayoutItemInterface
See Also:
alignment, QLayoutItem::setAlignment

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, PM_LayoutBottomMargin

setEnabled

public final void setEnabled(boolean arg__1)

Enables this layout if arg__1 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 method is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Sets the width of the outside border of the layout to arg__1.

Use setContentsMargins and getContentsMargins() instead.

See Also:
contentsRect, spacing

setMenuBar

public final void setMenuBar(QWidget w)

Tells the geometry manager to place the menu bar w 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)

Sets the resize mode of the layout to arg__1.

The default mode is SetDefaultConstraint.

See Also:
sizeConstraint

setWidgetSpacing

public final void setWidgetSpacing(int arg__1)

Sets the spacing between widgets inside the layout to arg__1.

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, it is possible to set different horizontal and vertical spacings using setHorizontalSpacing() and setVerticalSpacing(). In that case, spacing() returns -1.

See Also:
widgetSpacing, contentsRect, getContentsMargins, QStyle::layoutSpacing, QStyle::pixelMetric

sizeConstraint

public final QLayout.SizeConstraint sizeConstraint()

Returns the resize mode of the layout.

The default mode is SetDefaultConstraint.

See Also:
setSizeConstraint

widgetSpacing

public final int widgetSpacing()

Returns 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, it is possible to set different horizontal and vertical spacings using setHorizontalSpacing() and setVerticalSpacing(). In that case, spacing() returns -1.

See Also:
setWidgetSpacing, contentsRect, getContentsMargins, QStyle::layoutSpacing, QStyle::pixelMetric

totalHeightForWidth

public final int totalHeightForWidth(int w)


totalMaximumSize

public final QSize totalMaximumSize()


totalMinimumSize

public final QSize totalMinimumSize()


totalSizeHint

public final QSize totalSizeHint()


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, invalidate

widgetEvent

protected final void widgetEvent(QEvent arg__1)


addItem

public abstract void addItem(QLayoutItemInterface arg__1)

Implemented in subclasses to add an arg__1. 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 arg__1 is transferred to the layout, and it's the layout's responsibility to delete it.

See Also:
addWidget, QBoxLayout::addLayout, QGridLayout::addLayout

childEvent

protected void childEvent(QChildEvent e)

This function is reimplemented for internal reasons.

Overrides:
childEvent in class QObject
See Also:
event

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 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.

The default implementation returns Qt::Horizontal | Qt::Vertical. Subclasses reimplement it to return a meaningful value based on their child widgets's size policies.

Specified by:
expandingDirections in interface QLayoutItemInterface
See Also:
sizeHint

geometry

public QRect geometry()

This function is reimplemented for internal reasons.

Specified by:
geometry in interface QLayoutItemInterface
See Also:
setGeometry

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.

Specified by:
hasHeightForWidth in interface QLayoutItemInterface
See Also:
heightForWidth, QWidget::heightForWidth

heightForWidth

public int heightForWidth(int arg__1)

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

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:

    int MyLayout::heightForWidth(int w) const
    {
        if (cache_dirty || cached_width != w) {
            // not all C++ compilers support "mutable"
            MyLayout *that = (MyLayout*)this;
            int h = calculateHeightForWidth(w);
            that->cached_hfw = h;
            return h;
        }
        return cached_hfw;
    }

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

Specified by:
heightForWidth in interface QLayoutItemInterface
See Also:
hasHeightForWidth

indexOf

public int indexOf(QWidget arg__1)

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

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

The default implementation iterates over all items using itemAt


invalidate

public void invalidate()

This function is reimplemented for internal reasons.

Specified by:
invalidate in interface QLayoutItemInterface

isEmpty

public boolean isEmpty()

This function is reimplemented for internal reasons.

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, QLayoutItem *item)
    {
        QLayout *layout = item->layout();
        if (layout) {
            for (int i = 0; i < layout->count(); ++i)
                paintLayout(painter, layout->itemAt(i));
        }
        painter->drawRect(layout->geometry());
    }

    void MyWidget::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        if (layout())
            paintLayout(&painter, layout());
    }

See Also:
count, takeAt

layout

public QLayout layout()

This function is reimplemented for internal reasons.

Specified by:
layout in interface QLayoutItemInterface

maximumSize

public QSize maximumSize()

Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar.

The default implementation allows unlimited resizing.

Specified by:
maximumSize in interface QLayoutItemInterface

minimumHeightForWidth

public int minimumHeightForWidth(int arg__1)

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

Specified by:
minimumHeightForWidth in interface QLayoutItemInterface

minimumSize

public QSize minimumSize()

Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar.

The default implementation allows unlimited resizing.

Specified by:
minimumSize in interface QLayoutItemInterface

setGeometry

public abstract void setGeometry(QRect arg__1)

This function is reimplemented for internal reasons.

Specified by:
setGeometry in interface QLayoutItemInterface
See Also:
geometry

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:

    QLayoutItem *child;
    while ((child = layout->takeAt(0)) != 0) {
        ...
        delete child;
    }

See Also:
itemAt, 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 w, including heightForWidth and that is as close as possible to s.


fromNativePointer

public static QLayout fromNativePointer(QNativePointer nativePointer)
This function returns the QLayout instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

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.


Qt Jambi Home