QGraphicsAnchorLayout

注意

该类在 Qt4.6 引入

概要

函数

详细描述

PySide.QtGui.QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics View.

锚点布局允许开发者指定应如何相对彼此及布局本身,放置 Widget。制定规范是经由将锚点添加到布局,通过调用 PySide.QtGui.QGraphicsAnchorLayout.addAnchor() , PySide.QtGui.QGraphicsAnchorLayout.addAnchors() or PySide.QtGui.QGraphicsAnchorLayout.addCornerAnchors() .

可以访问布局中的现有锚点,采用 PySide.QtGui.QGraphicsAnchorLayout.anchor() function. Items that are anchored are automatically added to the layout, and if items are removed, all their anchors will be automatically removed.

UnknownCommand{class=”float-left”} .. image:: ../../../../../../qt-everywhere-opensource-src-4.8.5/doc/src/images/simpleanchorlayout-example.png UnknownCommand

Anchors are always set up between edges of an item, where the “center” is also considered to be an edge. Consider the following example:

layout.addAnchor(b, Qt.AnchorLeft, a, Qt.AnchorRight)
layout.addAnchor(b, Qt.AnchorTop, a, Qt.AnchorBottom)
										

Here, the right edge of item a is anchored to the left edge of item b and the bottom edge of item a is anchored to the top edge of item b , with the result that item b will be placed diagonally to the right and below item b .

PySide.QtGui.QGraphicsAnchorLayout.addCornerAnchors() function provides a simpler way of anchoring the corners of two widgets than the two individual calls to PySide.QtGui.QGraphicsAnchorLayout.addAnchor() shown in the code above. Here, we see how a widget can be anchored to the top-left corner of the enclosing layout:

layout.addCornerAnchors(a, Qt.TopLeftCorner, layout, Qt.TopLeftCorner)
										

In cases where anchors are used to match the widths or heights of widgets, it is convenient to use the PySide.QtGui.QGraphicsAnchorLayout.addAnchors() function. As with the other functions for specifying anchors, it can also be used to anchor a widget to a layout.


在锚点布局中的尺寸提示和尺寸策略

PySide.QtGui.QGraphicsAnchorLayout respects each item's size hints and size policies. Note that there are some properties of PySide.QtGui.QSizePolicy that are not respected .

在锚点布局中的间距

The layout may distribute some space between the items. If the spacing has not been explicitly specified, the actual amount of space will usually be 0.

However, if the first edge is the opposite of the second edge (e.g., the right edge of the first widget is anchored to the left edge of the second widget), the size of the anchor will be queried from the style through a pixel metric: PM_LayoutHorizontalSpacing for horizontal anchors and PM_LayoutVerticalSpacing for vertical anchors.

If the spacing is negative, the items will overlap to some extent.

已知问题

There are some features that PySide.QtGui.QGraphicsAnchorLayout currently does not support. This might change in the future, so avoid using these features if you want to avoid any future regressions in behaviour:

  • Stretch factors are not respected.
  • QSizePolicy.ExpandFlag is not respected.
  • Height for width is not respected.
class PySide.QtGui. QGraphicsAnchorLayout ( [ parent=None ] )
参数: parent PySide.QtGui.QGraphicsLayoutItem

构造 PySide.QtGui.QGraphicsAnchorLayout 实例。 parent 会被传递给 PySide.QtGui.QGraphicsLayout ‘s constructor.

PySide.QtGui.QGraphicsAnchorLayout. addAnchor ( firstItem , firstEdge , secondItem , secondEdge )
参数:
返回类型:

PySide.QtGui.QGraphicsAnchor

PySide.QtGui.QGraphicsAnchorLayout. addAnchors ( firstItem , secondItem [ , orientations=Qt.Horizontal | Qt.Vertical ] )
参数:
PySide.QtGui.QGraphicsAnchorLayout. addCornerAnchors ( firstItem , firstCorner , secondItem , secondCorner )
参数:
PySide.QtGui.QGraphicsAnchorLayout. anchor ( firstItem , firstEdge , secondItem , secondEdge )
参数:
返回类型:

PySide.QtGui.QGraphicsAnchor

PySide.QtGui.QGraphicsAnchorLayout. horizontalSpacing ( )
返回类型: PySide.QtCore.qreal

Returns the default horizontal spacing for the anchor layout.

PySide.QtGui.QGraphicsAnchorLayout. setHorizontalSpacing ( spacing )
参数: spacing PySide.QtCore.qreal

Sets the default horizontal spacing for the anchor layout to spacing .

PySide.QtGui.QGraphicsAnchorLayout. setSpacing ( spacing )
参数: spacing PySide.QtCore.qreal

Sets the default horizontal and the default vertical spacing for the anchor layout to spacing .

If an item is anchored with no spacing associated with the anchor, it will use the default spacing.

PySide.QtGui.QGraphicsAnchorLayout does not support negative spacings. Setting a negative value will unset the previous spacing and make the layout use the spacing provided by the current widget style.

PySide.QtGui.QGraphicsAnchorLayout. setVerticalSpacing ( spacing )
参数: spacing PySide.QtCore.qreal

Sets the default vertical spacing for the anchor layout to spacing .

PySide.QtGui.QGraphicsAnchorLayout. verticalSpacing ( )
返回类型: PySide.QtCore.qreal

Returns the default vertical spacing for the anchor layout.