继承者: QBoxLayout , QFormLayout , QGridLayout , QHBoxLayout , QStackedLayout , QVBoxLayout
def
activate
()
def
addChildLayout
(l)
def
addChildWidget
(w)
def
addWidget
(w)
def
adoptLayout
(layout)
def
alignmentRect
(arg__1)
def
contentsMargins
()
def
contentsRect
()
def
getContentsMargins
()
def
indexOf
(arg__1)
def
isEnabled
()
def
margin
()
def
menuBar
()
def
parentWidget
()
def
removeItem
(arg__1)
def
removeWidget
(w)
def
replaceWidget
(from, to[, options=Qt.FindChildrenRecursively])
def
setAlignment
(l, alignment)
def
setAlignment
(w, alignment)
def
setContentsMargins
(left, top, right, bottom)
def
setContentsMargins
(margins)
def
setEnabled
(arg__1)
def
setMargin
(arg__1)
def
setMenuBar
(w)
def
setSizeConstraint
(arg__1)
def
setSpacing
(arg__1)
def
sizeConstraint
()
def
spacing
()
def
totalHeightForWidth
(w)
def
totalMaximumSize
()
def
totalMinimumSize
()
def
totalSizeHint
()
def
update
()
def
widgetEvent
(arg__1)
def
closestAcceptableSize
(w, s)
这是被继承的抽象基类,由具体类
QBoxLayout,QGridLayout,QFormLayout,和QStackedLayout.For users of
QLayoutsubclasses or ofQMainWindowthere is seldom any need to use the basic functions provided byQLayout,譬如setSizeConstraint()orsetMenuBar()。见 布局管理 了解更多信息。To make your own layout manager, implement the functions
addItem(),sizeHint(),setGeometry(),itemAt()andtakeAt(). You should also implementminimumSize()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, implementhasHeightForWidth()andheightForWidth()。见 Border Layout and Flow Layout examples for more information about implementing custom layout managers.几何体管理停止,当布局管理器被删除时。
另请参阅
QLayout
¶
QLayout(parent)
- param parent
Constructs a new child
QLayout
.
This layout has to be inserted into another layout before geometry management will work.
Constructs a new top-level
QLayout
,采用父级
parent
.
parent
may not be
None
.
The layout is set directly as the top-level layout for
parent
. There can be only one top-level layout for a widget. It is returned by
layout()
.
PySide2.QtWidgets.QLayout.
SizeConstraint
¶
可能的值:
|
常量 |
描述 |
|---|---|
|
QLayout.SetDefaultConstraint |
The main widget’s minimum size is set to
|
|
QLayout.SetFixedSize |
The main widget’s size is set to
|
|
QLayout.SetMinimumSize |
The main widget’s minimum size is set to
|
|
QLayout.SetMaximumSize |
The main widget’s maximum size is set to
|
|
QLayout.SetMinAndMaxSize |
The main widget’s minimum size is set to
|
|
QLayout.SetNoConstraint |
Widget 不受约束。 |
另请参阅
PySide2.QtWidgets.QLayout.
activate
(
)
¶
bool
重做布局为
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.
另请参阅
PySide2.QtWidgets.QLayout.
addChildLayout
(
l
)
¶
l
–
QLayout
此函数被调用从
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.
PySide2.QtWidgets.QLayout.
addChildWidget
(
w
)
¶
w
–
QWidget
此函数被调用从
addWidget()
functions in 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.
PySide2.QtWidgets.QLayout.
addItem
(
arg__1
)
¶
arg__1
–
QLayoutItem
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.
PySide2.QtWidgets.QLayout.
addWidget
(
w
)
¶
w
–
QWidget
添加 Widget
w
to this layout in a manner specific to the layout. This function uses
addItem()
.
PySide2.QtWidgets.QLayout.
alignmentRect
(
arg__1
)
¶
arg__1
–
QRect
QRect
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
.
PySide2.QtWidgets.QLayout.
closestAcceptableSize
(
w
,
s
)
¶
w
–
QWidget
s
–
QSize
QSize
Returns a size that satisfies all size constraints on
widget
,包括
heightForWidth()
and that is as close as possible to
size
.
PySide2.QtWidgets.QLayout.
contentsMargins
(
)
¶
QMargins
返回围绕布局所使用的边距。
默认情况下,
QLayout
uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
另请参阅
PySide2.QtWidgets.QLayout.
contentsRect
(
)
¶
QRect
Returns the layout’s
geometry()
rectangle, but taking into account the contents margins.
PySide2.QtWidgets.QLayout.
count
(
)
¶
int
Must be implemented in subclasses to return the number of items in the layout.
另请参阅
PySide2.QtWidgets.QLayout.
getContentsMargins
(
)
¶
For each of
left
,
top
,
right
and
bottom
that is not
None
, stores the size of the margin named in the location the pointer refers to.
默认情况下,
QLayout
uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
另请参阅
setContentsMargins()
pixelMetric()
PM_LayoutLeftMargin
PM_LayoutTopMargin
PM_LayoutRightMargin
PM_LayoutBottomMargin
PySide2.QtWidgets.QLayout.
indexOf
(
arg__1
)
¶
arg__1
–
QLayoutItem
int
搜索布局项
layoutItem
在此布局 (不包括子级布局)。
Returns the index of
layoutItem
, or -1 if
layoutItem
找不到。
PySide2.QtWidgets.QLayout.
indexOf
(
arg__1
)
¶
arg__1
–
QWidget
int
搜索小部件
widget
在此布局 (不包括子级布局)。
Returns the index of
widget
, or -1 if
widget
找不到。
默认实现遍历所有项,使用
itemAt()
PySide2.QtWidgets.QLayout.
isEnabled
(
)
¶
bool
返回
true
若布局被启用;否则返回
false
.
另请参阅
PySide2.QtWidgets.QLayout.
itemAt
(
index
)
¶
index
–
int
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.
def paintLayout(self, painter, item):
layout = item.layout()
if layout:
for layout_item in layout:
self.paintLayout(painter, layout_item)
painter.drawRect(item.geometry())
def paintEvent(self, event):
painter = QPainter(self)
if self.layout():
self.paintLayout(painter, self.layout())
PySide2.QtWidgets.QLayout.
margin
(
)
¶
int
另请参阅
返回为此布局设置的菜单栏,或
None
若未设置菜单栏。
另请参阅
PySide2.QtWidgets.QLayout.
parentWidget
(
)
¶
返回此布局的父级 Widget,或
None
若此布局未安装在任何 Widget 中。
若布局是子布局,此函数返回父级布局的父级 Widget。
另请参阅
parent()
PySide2.QtWidgets.QLayout.
removeItem
(
arg__1
)
¶
arg__1
–
QLayoutItem
移除布局项
item
from the layout. It is the caller’s responsibility to delete the item.
预告:
item
可以是布局 (由于
QLayout
继承
QLayoutItem
).
另请参阅
PySide2.QtWidgets.QLayout.
removeWidget
(
w
)
¶
w
–
QWidget
移除 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 or to explicitly hide it if necessary.
注意
The ownership of
widget
remains the same as when it was added.
PySide2.QtWidgets.QLayout.
replaceWidget
(
from
,
to
[
,
options=Qt.FindChildrenRecursively
]
)
¶
搜索小部件
from
and replaces it with widget
to
if found. Returns the layout item that contains the widget
from
on success. Otherwise
None
被返回。若
options
contains
Qt::FindChildrenRecursively
(the default), sub-layouts are searched for doing the replacement. Any other flag in
options
被忽略。
Notice that the returned item therefore might not belong to this layout, but to a sub-layout.
The returned layout item is no longer owned by the layout and should be either deleted or inserted to another layout. The widget
from
is no longer managed by the layout and may need to be deleted or hidden. The parent of widget
from
is left unchanged.
This function works for the built-in Qt layouts, but might not work for custom layouts.
另请参阅
PySide2.QtWidgets.QLayout.
setAlignment
(
l
,
alignment
)
¶
l
–
QLayout
alignment
–
Alignment
bool
这是重载函数。
Sets the alignment for the layout
l
to
alignment
并返回
true
if
l
在此布局中被找到 (不包括子级布局);否则返回
false
.
PySide2.QtWidgets.QLayout.
setAlignment
(
w
,
alignment
)
¶
w
–
QWidget
alignment
–
Alignment
bool
Sets the alignment for widget
w
to
alignment
and returns true if
w
在此布局中被找到 (不包括子级布局);否则返回
false
.
PySide2.QtWidgets.QLayout.
setContentsMargins
(
margins
)
¶
margins
–
QMargins
设置
margins
以围绕布局使用。
默认情况下,
QLayout
uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.
另请参阅
PySide2.QtWidgets.QLayout.
setContentsMargins
(
left
,
top
,
right
,
bottom
)
¶
left
–
int
top
–
int
right
–
int
bottom
–
int
设置
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.
另请参阅
contentsMargins()
getContentsMargins()
pixelMetric()
PM_LayoutLeftMargin
PM_LayoutTopMargin
PM_LayoutRightMargin
PM_LayoutBottomMargin
PySide2.QtWidgets.QLayout.
setEnabled
(
arg__1
)
¶
arg__1
–
bool
启用此布局,若
enable
为 true,否则禁用它。
启用的布局会根据变化动态调整;禁用的布局就好像它不存在一样。
默认情况下,所有布局是启用的。
另请参阅
PySide2.QtWidgets.QLayout.
setMenuBar
(
w
)
¶
w
–
QWidget
Tells the geometry manager to place the menu bar
widget
at the top of
parentWidget()
, outside
contentsMargins()
. All child widgets are placed below the bottom edge of the menu bar.
另请参阅
PySide2.QtWidgets.QLayout.
setSizeConstraint
(
arg__1
)
¶
arg__1
–
SizeConstraint
另请参阅
PySide2.QtWidgets.QLayout.
sizeConstraint
(
)
¶
另请参阅
PySide2.QtWidgets.QLayout.
spacing
(
)
¶
int
另请参阅
PySide2.QtWidgets.QLayout.
takeAt
(
index
)
¶
index
–
int
必须在子类中实现以移除布局项,在
index
从布局,并返回项。若没有这样的项,函数必须什么都不做,并返回 0。项从 0 起被连续编号。若项被移除,其它项将被重新编号。
下列代码片段展示从布局,安全移除所有项的办法:
child = layout.takeAt(0)
while child:
...
del child
PySide2.QtWidgets.QLayout.
totalHeightForWidth
(
w
)
¶
w
–
int
int
Also takes
contentsMargins
and menu bar into account.
PySide2.QtWidgets.QLayout.
totalMaximumSize
(
)
¶
QSize
Also takes
contentsMargins
and menu bar into account.
PySide2.QtWidgets.QLayout.
totalMinimumSize
(
)
¶
QSize
Also takes
contentsMargins
and menu bar into account.
PySide2.QtWidgets.QLayout.
totalSizeHint
(
)
¶
QSize
Also takes
contentsMargins
and menu bar into account.
PySide2.QtWidgets.QLayout.
update
(
)
¶
更新布局为
parentWidget()
.
通常,不需要调用此,因为它会被自动调用 (在最合适时间)。
另请参阅
activate()
invalidate()
PySide2.QtWidgets.QLayout.
widgetEvent
(
arg__1
)
¶
arg__1
–
QEvent
Performs child widget layout when the parent widget is resized. Also handles removal of widgets.
e
is the event