Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QLayout class is the base class of geometry managers. More...
#include <QLayout>
Inherits QObject and QLayoutItem.
Inherited by QGridLayout, QBoxLayout, and QStackedLayout.
The QLayout class is the base class of geometry managers.
This is an abstract base class inherited by the concrete classes, QBoxLayout and QGridLayout.
For users of QLayout subclasses or of QMainWindow there is seldom any need to use the basic functions provided by QLayout, such as setResizeMode() or setMenuBar(). See the layout overview page 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 custom layout page for an in-depth description.
Geometry management stops when the layout manager is deleted.
The possible values are:
QLayout::Auto | If the main widget is a top-level widget with no height-for-width (hasHeightForWidth()), this is the same as Minimium; otherwise, this is the same as FreeResize. |
QLayout::Fixed | The main widget's size is set to sizeHint(); it cannot be resized at all. |
QLayout::Minimum | The main widget's minimum size is set to minimumSize(); it cannot be smaller. |
QLayout::FreeResize | The widget is not constrained. |
This property holds the width of the outside border of the layout.
Access functions:
See also spacing.
This property holds the resize mode of the layout.
The default mode is Auto.
Access functions:
See also QLayout::ResizeMode.
This property holds the spacing between widgets inside the layout.
The default value is -1, which signifies that the layout's spacing is inherited from the parent layout, or from the style settings for the parent widget.
Access functions:
See also margin.
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()
Constructs a new child QLayout, and places it inside parentLayout by using the default placement defined by addItem().
Constructs a new child QLayout.
This layout has to be inserted into another layout before geometry management will work.
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.
See also update() and QWidget::updateGeometry().
This function is called from addLayout() functions in subclasses to add layout l as a sub-layout.
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.
Implemented in subclasses to add an item. How it is added is specific to each subclass.
The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.
Adds widget w to this layout in a manner specific to the layout. This function uses addItem().
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.
Returns a size that satisfies all size constraints on w, including heightForWidth() and that is as close as possible to s.
Removes and deletes all items in this layout.
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 BothDirections means that it wants to grow in both dimensions.
The default implementation returns BothDirections.
Reimplemented from QLayoutItem.
Sets this layout's parent widget to a fixed size with width w and height h, stopping the user form resizing it, and also prevents the layout from resizing it, even if the layout's size hint should change. Does nothing if this is not a toplevel layout (isTopLevel() returns true).
As a special case, if both w and h are 0, then the layout's current sizeHint() is used.
Use setResizeMode(Fixed) to stop the widget from being resized by the user, while still allowing the layout to resize it when the sizeHint() changes.
Use setResizeMode(FreeResize) to allow the user to resize the widget, while preventing the layout from resizing it.
Invalidates cached information. Reimplementations must call this.
Reimplemented from QLayoutItem.
Returns true if this layout is empty. The default implementation returns false.
Reimplemented from QLayoutItem.
Returns true if the layout is enabled; otherwise returns false.
See also setEnabled().
Returns true if this layout is a top-level layout, i.e. not a child of another layout; otherwise returns false.
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 *p, QLayoutItem *item) { QLayout *layout = item->layout(); if (layout) { QLayoutItem *child; int i = 0; while ((child = layout->itemAt(i)) != 0) { paintLayout(p, child); ++i; } } p->drawRect(lay->geometry()); } void ExampleWidget::paintEvent(QPaintEvent *) { QPainter p(this); if (layout()) paintLayout(&p, layout()); }
See also QLayout::takeAt().
Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications. Does not include what's needed by QWidget::setContentsMargins() or menuBar().
The default implementation allows unlimited resizing.
Reimplemented from QLayoutItem.
Returns the menu bar set for this layout, or 0 if no menu bar is set.
Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications. Does not include what's needed by QWidget::setContentsMargins() or menuBar().
The default implementation allows unlimited resizing.
Reimplemented from QLayoutItem.
Returns the parent widget of this layout, or 0 if this layout is a sub-layout that is not yet inserted.
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().
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.
See also removeItem(), QWidget::setGeometry(), and addWidget().
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().
This function is reimplemented in subclasses to perform layout.
The default implementation maintains the geometry() information given by rect r. Reimplementors must call this function.
Reimplemented from QLayoutItem.
Makes the geometry manager take account of the menu bar w. All child widgets are placed below the bottom edge of the menu bar.
A menu bar does its own geometry management: never do addWidget() on a QMenuBar.
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) { //process child... }
See also QLayout::itemAt().
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().
Copyright © 2004 Trolltech | Trademarks | Qt 4.0.0-b1 |