![]() |
CopperSpice API
1.9.2
|
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics View. More...
Protected Methods | |
QSizeF | sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF ()) const override |
![]() | |
void | addChildLayoutItem (QGraphicsLayoutItem *layoutItem) |
![]() | |
void | setGraphicsItem (QGraphicsItem *item) |
void | setOwnedByLayout (bool owner) |
Friends | |
class | QGraphicsAnchor |
Additional Inherited Members | |
![]() | |
static bool | instantInvalidatePropagation () |
static void | setInstantInvalidatePropagation (bool enable) |
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics View. The anchor layout allows developers to specify how widgets should be placed relative to each other, and to the layout itself. The specification is made by adding anchors to the layout by calling addAnchor(), addAnchors() or addCornerAnchors().
Existing anchors in the layout can be accessed with the anchor() function. Items that are anchored are automatically added to the layout, and if items are removed, all their anchors will be automatically removed.
QGraphicsAnchorLayout::QGraphicsAnchorLayout | ( | QGraphicsLayoutItem * | parent = nullptr | ) |
Constructs a QGraphicsAnchorLayout instance. The parent object is passed to the QGraphicsLayout constructor.
|
virtual |
Destroys the QGraphicsAnchorLayout object.
QGraphicsAnchor * QGraphicsAnchorLayout::addAnchor | ( | QGraphicsLayoutItem * | firstItem, |
Qt::AnchorPoint | firstEdge, | ||
QGraphicsLayoutItem * | secondItem, | ||
Qt::AnchorPoint | secondEdge | ||
) |
Creates an anchor between the edge firstEdge of item firstItem and the edge secondEdge of item secondItem. The spacing of the anchor is picked up from the style. Anchors between a layout edge and an item edge will have a size of 0. If there is already an anchor between the edges, the new anchor will replace the old one.
The firstItem and secondItem are automatically added to the layout if they are not part of the layout. This means that count() can increase by up to 2.
The spacing an anchor will get depends on the type of anchor. For instance, anchors from the Right edge of one item to the Left edge of another (or vice versa) will use the default horizontal spacing. The same behavior applies to Bottom to Top anchors, (but they will use the default vertical spacing). For all other anchor combinations, the spacing will be 0. All anchoring functions will follow this rule.
The spacing can also be set manually by using QGraphicsAnchor::setSpacing() method. Calling this method where firstItem or secondItem are ancestors of the layout will is undefined behavior.
void QGraphicsAnchorLayout::addAnchors | ( | QGraphicsLayoutItem * | firstItem, |
QGraphicsLayoutItem * | secondItem, | ||
Qt::Orientations | orientations = Qt::Horizontal | Qt::Vertical |
||
) |
Anchors two or four edges of firstItem with the corresponding edges of secondItem, so that firstItem has the same size as secondItem in the dimensions specified by orientations.
For example, the following example anchors the left and right edges of two items to match their widths.
This can also be achieved using the following line of code:
void QGraphicsAnchorLayout::addCornerAnchors | ( | QGraphicsLayoutItem * | firstItem, |
Qt::Corner | firstCorner, | ||
QGraphicsLayoutItem * | secondItem, | ||
Qt::Corner | secondCorner | ||
) |
Creates two anchors between firstItem and secondItem specified by the corners, firstCorner and secondCorner, where one is for the horizontal edge and another one for the vertical edge. If there is already an anchor between the edge pairs, it will be replaced by the anchors that this method specifies. The values for firstItem and secondItem are automatically added to the layout if they are not part of the layout. This means count() can increase by up to 2.
Since anchoring corners can be expressed as anchoring two edges, the following examples are equivalent.
QGraphicsAnchor * QGraphicsAnchorLayout::anchor | ( | QGraphicsLayoutItem * | firstItem, |
Qt::AnchorPoint | firstEdge, | ||
QGraphicsLayoutItem * | secondItem, | ||
Qt::AnchorPoint | secondEdge | ||
) |
Returns the anchor between the anchor points defined by firstItem, firstEdge, and secondItem, secondEdge. If there is no such anchor the method will return a nullptr.
|
overridevirtual |
Implements QGraphicsLayout::count()
qreal QGraphicsAnchorLayout::horizontalSpacing | ( | ) | const |
Returns the default horizontal spacing for the anchor layout.
|
overridevirtual |
Reimplemented from QGraphicsLayout::invalidate()
|
overridevirtual |
Implements QGraphicsLayout::itemAt()
|
overridevirtual |
Removes the layout item at index without destroying it. Ownership of the item is transferred to the caller. Removing an item will also remove any of the anchors associated with it.
Implements QGraphicsLayout::removeAt()
|
overridevirtual |
Reimplemented from QGraphicsLayoutItem::setGeometry()
void QGraphicsAnchorLayout::setHorizontalSpacing | ( | qreal | spacing | ) |
Sets the default horizontal spacing for the anchor layout to spacing.
void QGraphicsAnchorLayout::setSpacing | ( | qreal | spacing | ) |
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. 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.
void QGraphicsAnchorLayout::setVerticalSpacing | ( | qreal | spacing | ) |
Sets the default vertical spacing for the anchor layout to spacing.
|
overrideprotectedvirtual |
Implements QGraphicsLayoutItem::sizeHint()
qreal QGraphicsAnchorLayout::verticalSpacing | ( | ) | const |
Returns the default vertical spacing for the anchor layout.