|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QLayout
public abstract class QLayout
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.
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 |
---|
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().
public QLayout()
Constructs a new child QLayout.
This layout has to be inserted into another layout before geometry management will work.
Method Detail |
---|
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.
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.
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.
public final void addWidget(QWidget w)
Adds widget w to this layout in a manner specific to the layout. This function uses addItem.
public final Qt.Alignment alignment()
Returns the alignment of this item.
alignment
in interface QLayoutItemInterface
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.
public final QRect contentsRect()
Returns the layout's geometry rectangle, but taking into account the contents margins.
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.
controlTypes
in interface QLayoutItemInterface
public final boolean isEnabled()
Returns true if the layout is enabled; otherwise returns false.
public final QWidget menuBar()
Returns the menu bar set for this layout, or 0 if no menu bar is set.
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.
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).
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.
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.
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.
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.
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.
public final void setAlignment(Qt.Alignment alignment)
Sets the alignment of this item to alignment.
setAlignment
in interface QLayoutItemInterface
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.
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.
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.
spacing
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.
public final void setSizeConstraint(QLayout.SizeConstraint arg__1)
Sets the resize mode of the layout to arg__1.
The default mode is SetDefaultConstraint.
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.
public final QLayout.SizeConstraint sizeConstraint()
Returns the resize mode of the layout.
The default mode is SetDefaultConstraint.
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.
public final int totalHeightForWidth(int w)
public final QSize totalMaximumSize()
public final QSize totalMinimumSize()
public final QSize totalSizeHint()
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.
protected final void widgetEvent(QEvent arg__1)
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.
protected void childEvent(QChildEvent e)
This function is reimplemented for internal reasons.
childEvent
in class QObject
public abstract int count()
Must be implemented in subclasses to return the number of items in the layout.
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.
expandingDirections
in interface QLayoutItemInterface
public QRect geometry()
This function is reimplemented for internal reasons.
geometry
in interface QLayoutItemInterface
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.
hasHeightForWidth
in interface QLayoutItemInterface
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.
heightForWidth
in interface QLayoutItemInterface
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
public void invalidate()
This function is reimplemented for internal reasons.
invalidate
in interface QLayoutItemInterface
public boolean isEmpty()
This function is reimplemented for internal reasons.
isEmpty
in interface QLayoutItemInterface
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()); }
public QLayout layout()
This function is reimplemented for internal reasons.
layout
in interface QLayoutItemInterface
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.
maximumSize
in interface QLayoutItemInterface
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).
minimumHeightForWidth
in interface QLayoutItemInterface
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.
minimumSize
in interface QLayoutItemInterface
public abstract void setGeometry(QRect arg__1)
This function is reimplemented for internal reasons.
setGeometry
in interface QLayoutItemInterface
public abstract QSize sizeHint()
Implemented in subclasses to return the preferred size of this item.
sizeHint
in interface QLayoutItemInterface
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.
spacerItem
in interface QLayoutItemInterface
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; }
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.
widget
in interface QLayoutItemInterface
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.
public static QLayout fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public final QContentsMargins getContentsMargins()
public final void setContentsMargins(QContentsMargins margins)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |