QGraphicsLinearLayout

概要

函数

详细描述

PySide.QtGui.QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View.

The default orientation for a linear layout is Qt.Horizontal . You can choose a vertical orientation either by calling PySide.QtGui.QGraphicsLinearLayout.setOrientation() , or by passing Qt.Vertical to PySide.QtGui.QGraphicsLinearLayout ‘s constructor.

The most common way to use PySide.QtGui.QGraphicsLinearLayout is to construct an object on the heap with no parent, add widgets and layouts by calling PySide.QtGui.QGraphicsLinearLayout.addItem() , and finally assign the layout to a widget by calling QGraphicsWidget.setLayout() .

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 ( PySide.QtGui.QGraphicsLinearLayout.addStretch() , PySide.QtGui.QGraphicsLinearLayout.insertStretch() or PySide.QtGui.QGraphicsLinearLayout.setStretchFactor() ), and spacings ( PySide.QtGui.QGraphicsLinearLayout.setItemSpacing() ) to a linear layout. The layout takes ownership of the items. In some cases when the layout item also inherits from PySide.QtGui.QGraphicsItem (譬如 PySide.QtGui.QGraphicsWidget ) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation of QGraphicsLayoutItem.setOwnedByLayout() how to handle this. You can access each item in the layout by calling PySide.QtGui.QGraphicsLinearLayout.count() and PySide.QtGui.QGraphicsLinearLayout.itemAt() 。调用 PySide.QtGui.QGraphicsLinearLayout.removeAt() or PySide.QtGui.QGraphicsLinearLayout.removeItem() will remove an item from the layout, without destroying it.

在 QGraphicsLinearLayout 中的尺寸提示和尺寸策略

PySide.QtGui.QGraphicsLinearLayout respects 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 calling PySide.QtGui.QGraphicsLinearLayout.setAlignment() , and check the alignment for any item by calling PySide.QtGui.QGraphicsLinearLayout.alignment() . By default, items are aligned to the top left.

在 QGraphicsLinearLayout 中的间距

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 PySide.QtGui.QGraphicsLinearLayout.setSpacing() , and get the current spacing value by calling PySide.QtGui.QGraphicsLinearLayout.spacing() . If you want to configure individual spacing for your items, you can call PySide.QtGui.QGraphicsLinearLayout.setItemSpacing() .

在 QGraphicsLinearLayout 中的拉伸因子

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.

PySide.QtGui.QGraphicsLinearLayout calculates 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 use PySide.QtGui.QGraphicsGridLayout 代替。

QGraphicsLinearLayout 相比其它布局

class PySide.QtGui. QGraphicsLinearLayout ( [ parent=None ] )
class PySide.QtGui. QGraphicsLinearLayout ( orientation [ , parent=None ] )
参数:

构造 PySide.QtGui.QGraphicsLinearLayout instance using Qt.Horizontal orientation. parent 会被传递给 PySide.QtGui.QGraphicsLayout ‘s constructor.

PySide.QtGui.QGraphicsLinearLayout. addItem ( item )
参数: item PySide.QtGui.QGraphicsLayoutItem

This convenience function is equivalent to calling insertItem(-1, item ).

PySide.QtGui.QGraphicsLinearLayout. addStretch ( [ stretch=1 ] )
参数: stretch PySide.QtCore.int

This convenience function is equivalent to calling insertStretch(-1, stretch ).

PySide.QtGui.QGraphicsLinearLayout. alignment ( item )
参数: item PySide.QtGui.QGraphicsLayoutItem
返回类型: PySide.QtCore.Qt.Alignment

返回对齐方式为 item . The default alignment is Qt.AlignTop | Qt.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.

PySide.QtGui.QGraphicsLinearLayout. dump ( [ indent=0 ] )
参数: indent PySide.QtCore.int
PySide.QtGui.QGraphicsLinearLayout. insertItem ( index , item )
参数:

插入 item into the layout at index , or before any item that is currently at index .

PySide.QtGui.QGraphicsLinearLayout. insertStretch ( index [ , stretch=1 ] )
参数:
  • index PySide.QtCore.int
  • stretch PySide.QtCore.int

Inserts a stretch of stretch at index , or before any item that is currently at index .

PySide.QtGui.QGraphicsLinearLayout. itemSpacing ( index )
参数: index PySide.QtCore.int
返回类型: PySide.QtCore.qreal

Returns the spacing after item at index .

PySide.QtGui.QGraphicsLinearLayout. orientation ( )
返回类型: PySide.QtCore.Qt.Orientation

Returns the layout orientation.

PySide.QtGui.QGraphicsLinearLayout. removeItem ( item )
参数: item PySide.QtGui.QGraphicsLayoutItem

移除 item from the layout without destroying it. Ownership of item is transferred to the caller.

另请参阅

PySide.QtGui.QGraphicsLinearLayout.removeAt() PySide.QtGui.QGraphicsLinearLayout.insertItem()

PySide.QtGui.QGraphicsLinearLayout. setAlignment ( item , alignment )
参数:
PySide.QtGui.QGraphicsLinearLayout. setItemSpacing ( index , spacing )
参数:
  • index PySide.QtCore.int
  • spacing PySide.QtCore.qreal

Sets the spacing after item at index to spacing .

PySide.QtGui.QGraphicsLinearLayout. setOrientation ( orientation )
参数: orientation PySide.QtCore.Qt.Orientation
PySide.QtGui.QGraphicsLinearLayout. setSpacing ( spacing )
参数: spacing PySide.QtCore.qreal

Sets the layout's spacing to spacing . Spacing refers to the vertical and horizontal distances between items.

PySide.QtGui.QGraphicsLinearLayout. setStretchFactor ( item , stretch )
参数:

设置拉伸因子为 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.

PySide.QtGui.QGraphicsLinearLayout. spacing ( )
返回类型: PySide.QtCore.qreal

Returns the layout's spacing. Spacing refers to the vertical and horizontal distances between items.

PySide.QtGui.QGraphicsLinearLayout. stretchFactor ( item )
参数: item PySide.QtGui.QGraphicsLayoutItem
返回类型: PySide.QtCore.int

Returns the stretch factor for item . The default stretch factor is 0, meaning that the item has no assigned stretch factor.