QLayout 类是几何管理器的基类。 更多...
继承 QObject and QLayoutItem .
Inherited by QBoxLayout , QFormLayout , QGridLayout and QStackedLayout .
QLayout 类是几何管理器的基类。
这是被继承的抽象基类,由具体类 QBoxLayout , QGridLayout , QFormLayout ,和 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 () 或 setMenuBar ()。见 布局管理 了解更多信息。
To make your own layout manager, implement the functions addItem (), sizeHint (), setGeometry (), itemAt () 和 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 () 和 heightForWidth ()。见 the Border Layout and Flow Layout examples for more information about implementing custom layout managers.
Geometry management stops when the layout manager is deleted.
可能的值:
| 常量 | 值 | 描述 |
|---|---|---|
| QLayout.SetDefaultConstraint | 0 | The main widget's minimum size is set to minimumSize (), unless the widget already has a minimum size. |
| QLayout.SetFixedSize | 3 | The main widget's size is set to sizeHint (); it cannot be resized at all. |
| QLayout.SetMinimumSize | 2 | The main widget's minimum size is set to minimumSize (); it cannot be smaller. |
| QLayout.SetMaximumSize | 4 | The main widget's maximum size is set to maximumSize (); it cannot be larger. |
| QLayout.SetMinAndMaxSize | 5 | The main widget's minimum size is set to minimumSize () and its maximum size is set to maximumSize (). |
| QLayout.SetNoConstraint | 1 | Widget 不受约束。 |
另请参阅 setSizeConstraint ().
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs a new top-level QLayout , 采用父级 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 .
This layout has to be inserted into another layout before geometry management will work.
重做布局为 parentWidget () 若有必要。
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.
另请参阅 update () 和 QWidget.updateGeometry ().
l argument has it's ownership transferred to Qt.
此函数被调用从 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.
另请参阅 QBoxLayout.addLayout (), QBoxLayout.insertLayout (),和 QGridLayout.addLayout ().
此函数被调用从 addWidget() 函数在 subclasses to add w as a managed widget of a layout.
若 w is already managed by a layout, this function will give a warning and remove w from that layout. This function must therefore be called before adding w to the layout's data structure.
This method is abstract and should be reimplemented in any sub-class.
QLayoutItem argument has it's ownership transferred to Qt.
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 子类。
注意: The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.
另请参阅 addWidget (), QBoxLayout.addLayout (),和 QGridLayout.addLayout ().
添加 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 .
重实现自 QObject.childEvent ().
Returns a size that satisfies all size constraints on widget ,包括 heightForWidth () and that is as close as possible to size .
返回围绕布局所使用的边距。
默认情况下, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
该函数在 Qt 4.6 引入。
另请参阅 setContentsMargins ().
返回布局的 geometry () rectangle, but taking into account the contents margins.
该函数在 Qt 4.3 引入。
另请参阅 setContentsMargins () 和 getContentsMargins ().
This method is abstract and should be reimplemented in any sub-class.
Must be implemented in subclasses to return the number of items in the layout.
另请参阅 itemAt ().
重实现自 QLayoutItem.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.
默认实现返回 Qt.Horizontal | Qt.Vertical . Subclasses reimplement it to return a meaningful value based on their child widgets's size policies .
另请参阅 sizeHint ().
重实现自 QLayoutItem.geometry ().
另请参阅 setGeometry ().
Extracts the left, top, right, and bottom margins used around the layout, and assigns them to * left , * top , * right , and * bottom (unless they are null pointers).
默认情况下, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
该函数在 Qt 4.3 引入。
另请参阅 setContentsMargins (), QStyle.pixelMetric (), PM_LayoutLeftMargin , PM_LayoutTopMargin , PM_LayoutRightMargin , and PM_LayoutBottomMargin .
搜索小部件 widget in this layout (not including child layouts).
Returns the index of widget , or -1 if widget is not found.
默认实现遍历所有项,使用 itemAt ()
重实现自 QLayoutItem.invalidate ().
重实现自 QLayoutItem.isEmpty ().
Returns true if the layout is enabled; otherwise returns false.
另请参阅 setEnabled ().
This method is abstract and should be reimplemented in any sub-class.
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(item->geometry()); } void MyWidget.paintEvent(QPaintEvent *) { QPainter painter(this); if (layout()) paintLayout(&painter, layout()); }
重实现自 QLayoutItem.layout ().
重实现自 QLayoutItem.maximumSize ().
Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the 规范。
The returned value doesn't include the space required by QWidget.setContentsMargins () or menuBar ().
默认实现允许无限重置尺寸。
Returns the menu bar set for this layout, or 0 if no menu bar is set.
另请参阅 setMenuBar ().
重实现自 QLayoutItem.minimumSize ().
Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the 规范。
The returned value doesn't include the space required by QWidget.setContentsMargins () or menuBar ().
默认实现允许无限重置尺寸。
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.
另请参阅 parent ().
QLayoutItem argument
移除布局项 item from the layout. It is the caller's responsibility to delete the item.
注意: item 可以是布局 (由于 QLayout 继承 QLayoutItem ).
另请参阅 removeWidget () 和 addItem ().
移除 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.
注意: The ownership of widget remains the same as when it was added.
另请参阅 removeItem (), QWidget.setGeometry (),和 addWidget ().
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.
把此项的对齐方式设为 alignment .
另请参阅 QLayoutItem.setAlignment ().
这是重载函数。
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.
设置 left , top , right ,和 bottom margins to use around the layout.
默认情况下, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
该函数在 Qt 4.3 引入。
另请参阅 contentsMargins (), getContentsMargins (), QStyle.pixelMetric (), PM_LayoutLeftMargin , PM_LayoutTopMargin , PM_LayoutRightMargin , and PM_LayoutBottomMargin .
设置 margins 以围绕布局使用。
默认情况下, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
该函数在 Qt 4.6 引入。
另请参阅 contentsMargins ().
启用此布局,若 enable is true, otherwise disables it.
An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.
默认情况下,所有布局是启用的。
另请参阅 isEnabled ().
重实现自 QLayoutItem.setGeometry ().
另请参阅 geometry ().
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.
另请参阅 menuBar ().
This method is abstract and should be reimplemented in any sub-class.
QLayoutItem result
必须在子类中实现以移除布局项,在 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 removed, 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; }
更新布局为 parentWidget ().
You should generally not need to call this because it is automatically called at the most appropriate times.
另请参阅 activate () and invalidate ().