QGraphicsLinearLayoutclass provides a horizontal or vertical layout for managing widgets in Graphics View. 更多 …
def
addItem
(item)
def
addStretch
([stretch=1])
def
alignment
(item)
def
dump
([indent=0])
def
insertItem
(index, item)
def
insertStretch
(index[, stretch=1])
def
itemSpacing
(index)
def
orientation
()
def
removeItem
(item)
def
setAlignment
(item, alignment)
def
setItemSpacing
(index, spacing)
def
setOrientation
(orientation)
def
setSpacing
(spacing)
def
setStretchFactor
(item, stretch)
def
spacing
()
def
stretchFactor
(item)
The default orientation for a linear layout is
Horizontal. You can choose a vertical orientation either by callingsetOrientation(), or by passingVerticaltoQGraphicsLinearLayout‘s constructor.The most common way to use
QGraphicsLinearLayoutis to construct an object on the heap with no parent, add widgets and layouts by callingaddItem(), and finally assign the layout to a widget by callingsetLayout().scene = QGraphicsScene() textEdit = scene.addWidget(QTextEdit()) pushButton = scene.addWidget(QPushButton()) layout = QGraphicsLinearLayout() layout.addItem(textEdit) layout.addItem(pushButton) form = QGraphicsWidget() form.setLayout(layout) scene.addItem(form)You can add widgets, layouts, stretches (
addStretch(),insertStretch()orsetStretchFactor()), and spacings (setItemSpacing()) to a linear layout. The layout takes ownership of the items. In some cases when the layout item also inherits fromQGraphicsItem(譬如 QGraphicsWidget ) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation ofsetOwnedByLayout()how to handle this. You can access each item in the layout by callingcount()anditemAt()。调用removeAt()orremoveItem()will remove an item from the layout, without destroying it.
QGraphicsLinearLayoutrespects each item’s size hints and size policies, and when the layout contains more space than the items can fill, each item is arranged according to the layout’s alignment for that item. You can set an alignment for each item by callingsetAlignment(), and check the alignment for any item by callingalignment(). By default, items are aligned to the top left.
Between the items, the layout distributes some space. The actual amount of space depends on the managed widget’s current style, but the common spacing is 4. You can also set your own spacing by calling
setSpacing(), and get the current spacing value by callingspacing(). If you want to configure individual spacing for your items, you can callsetItemSpacing().
You can assign a stretch factor to each item to control how much space it will get compared to the other items. By default, two identical widgets arranged in a linear layout will have the same size, but if the first widget has a stretch factor of 1 and the second widget has a stretch factor of 2, the first widget will get 1/3 of the available space, and the second will get 2/3.
QGraphicsLinearLayoutcalculates the distribution of sizes by adding up the stretch factors of all items, and then dividing the available space accordingly. The default stretch factor is 0 for all items; a factor of 0 means the item does not have any defined stretch factor; effectively this is the same as setting the stretch factor to 1. The stretch factor only applies to the available space in the lengthwise direction of the layout (following its orientation). If you want to control both the item’s horizontal and vertical stretch, you can useQGraphicsGridLayout代替。
QGraphicsLinearLayout非常类似QVBoxLayoutandQHBoxLayout, but in contrast to these classes, it is used to manage QGraphicsWidget and QGraphicsLayout 而不是QWidgetandQLayout.
QGraphicsLinearLayout
(
[
parent=None
]
)
¶
QGraphicsLinearLayout(orientation[, parent=None])
- param parent
- param orientation
取向
构造
QGraphicsLinearLayout
instance using
Horizontal
orientation.
parent
会被传递给
QGraphicsLayout
‘s constructor.
构造
QGraphicsLinearLayout
instance. You can pass the
orientation
for the layout, either horizontal or vertical, and
parent
会被传递给
QGraphicsLayout
‘s constructor.
PySide2.QtWidgets.QGraphicsLinearLayout.
addItem
(
item
)
¶
item
–
QGraphicsLayoutItem
This convenience function is equivalent to calling
insertItem
(-1,
item
).
PySide2.QtWidgets.QGraphicsLinearLayout.
addStretch
(
[
stretch=1
]
)
¶
stretch
–
int
This convenience function is equivalent to calling
insertStretch
(-1,
stretch
).
PySide2.QtWidgets.QGraphicsLinearLayout.
alignment
(
item
)
¶
item
–
QGraphicsLayoutItem
Alignment
返回对齐方式为
item
. The default alignment is
AlignTop
|
AlignLeft
.
The alignment decides how the item is positioned within its assigned space in the case where there’s more space available in the layout than the widgets can occupy.
另请参阅
PySide2.QtWidgets.QGraphicsLinearLayout.
dump
(
[
indent=0
]
)
¶
indent
–
int
PySide2.QtWidgets.QGraphicsLinearLayout.
insertItem
(
index
,
item
)
¶
index
–
int
item
–
QGraphicsLayoutItem
插入
item
into the layout at
index
, or before any item that is currently at
index
.
另请参阅
addItem()
itemAt()
insertStretch()
setItemSpacing()
PySide2.QtWidgets.QGraphicsLinearLayout.
insertStretch
(
index
[
,
stretch=1
]
)
¶
index
–
int
stretch
–
int
Inserts a stretch of
stretch
at
index
, or before any item that is currently at
index
.
PySide2.QtWidgets.QGraphicsLinearLayout.
itemSpacing
(
index
)
¶
index
–
int
qreal
Returns the spacing after item at
index
.
另请参阅
PySide2.QtWidgets.QGraphicsLinearLayout.
orientation
(
)
¶
取向
Returns the layout orientation.
另请参阅
PySide2.QtWidgets.QGraphicsLinearLayout.
removeItem
(
item
)
¶
item
–
QGraphicsLayoutItem
移除
item
from the layout without destroying it. Ownership of
item
is transferred to the caller.
另请参阅
removeAt()
insertItem()
PySide2.QtWidgets.QGraphicsLinearLayout.
setAlignment
(
item
,
alignment
)
¶
item
–
QGraphicsLayoutItem
alignment
–
Alignment
Sets the alignment of
item
to
alignment
。若
item
‘s alignment changes, the layout is automatically invalidated.
另请参阅
alignment()
invalidate()
PySide2.QtWidgets.QGraphicsLinearLayout.
setItemSpacing
(
index
,
spacing
)
¶
index
–
int
spacing
–
qreal
Sets the spacing after item at
index
to
spacing
.
另请参阅
PySide2.QtWidgets.QGraphicsLinearLayout.
setOrientation
(
orientation
)
¶
orientation
–
取向
Change the layout orientation to
orientation
. Changing the layout orientation will automatically invalidate the layout.
另请参阅
PySide2.QtWidgets.QGraphicsLinearLayout.
setSpacing
(
spacing
)
¶
spacing
–
qreal
Sets the layout’s spacing to
spacing
. Spacing refers to the vertical and horizontal distances between items.
PySide2.QtWidgets.QGraphicsLinearLayout.
setStretchFactor
(
item
,
stretch
)
¶
item
–
QGraphicsLayoutItem
stretch
–
int
设置拉伸因子为
item
to
stretch
. If an item’s stretch factor changes, this function will invalidate the layout.
设置
stretch
to 0 removes the stretch factor from the item, and is effectively equivalent to setting
stretch
to 1.
另请参阅
PySide2.QtWidgets.QGraphicsLinearLayout.
spacing
(
)
¶
qreal
Returns the layout’s spacing. Spacing refers to the vertical and horizontal distances between items.
另请参阅
PySide2.QtWidgets.QGraphicsLinearLayout.
stretchFactor
(
item
)
¶
item
–
QGraphicsLayoutItem
int
Returns the stretch factor for
item
. The default stretch factor is 0, meaning that the item has no assigned stretch factor.
另请参阅