![]() |
Home · All Classes · All Functions · Overviews |
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics View. More...
#include <QGraphicsAnchorLayout>
Inherits QGraphicsLayout.
This class was introduced in Qt 4.6.
QGraphicsAnchorLayout ( QGraphicsLayoutItem * parent = 0 ) | |
virtual | ~QGraphicsAnchorLayout () |
QGraphicsAnchor * | addAnchor ( QGraphicsLayoutItem * firstItem, Qt::AnchorPoint firstEdge, QGraphicsLayoutItem * secondItem, Qt::AnchorPoint secondEdge ) |
void | addAnchors ( QGraphicsLayoutItem * firstItem, QGraphicsLayoutItem * secondItem, Qt::Orientations orientations = Qt::Horizontal | Qt::Vertical ) |
void | addCornerAnchors ( QGraphicsLayoutItem * firstItem, Qt::Corner firstCorner, QGraphicsLayoutItem * secondItem, Qt::Corner secondCorner ) |
QGraphicsAnchor * | anchor ( QGraphicsLayoutItem * firstItem, Qt::AnchorPoint firstEdge, QGraphicsLayoutItem * secondItem, Qt::AnchorPoint secondEdge ) |
qreal | horizontalSpacing () const |
void | setHorizontalSpacing ( qreal spacing ) |
void | setSpacing ( qreal spacing ) |
void | setVerticalSpacing ( qreal spacing ) |
qreal | verticalSpacing () const |
virtual int | count () const |
virtual void | invalidate () |
virtual QGraphicsLayoutItem * | itemAt ( int index ) const |
virtual void | removeAt ( int index ) |
virtual void | setGeometry ( const QRectF & geom ) |
virtual QSizeF | sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const |
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics View.
The anchor layout is a layout where one can specify how widgets should be placed relative to each other. The specification is called an anchor, and it is set up by calling anchor(). Anchors are always set up between edges of an item, where the "center" is also considered to be an edge. Considering this example:
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; QGraphicsWidget *a = new QGraphicsWidget; QGraphicsWidget *b = new QGraphicsWidget; l->anchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
Here is the right edge of item A anchored to the left edge of item B, with the result that item B will be placed to the right of item A, with a spacing between A and B. If the spacing is negative, the items will overlap to some extent. Items that are anchored are automatically added to the layout, and if items are removed, all their anchors will be automatically removed
QGraphicsAnchorLayout respects each item's size hints and size policies. However it does not respect stretch factors currently. This might change in the future, so please refrain from using stretch factors in anchor layout to avoid any future regressions.
Between the items, the layout can distribute some space. If the spacing has not been explicitly specified, the actual amount of space will usually be 0, but if the first edge is the "opposite" of the second edge (i.e. Right is anchored to Left or vice-versa), the size of the anchor will be queried from the style through the pixelMetric PM_LayoutHorizontalSpacing (or PM_LayoutVerticalSpacing for vertical anchors).
Constructs a QGraphicsAnchorLayout instance. parent is passed to QGraphicsLayout's constructor.
Destroys the QGraphicsAnchorLayout object.
Creates an anchor between the edge firstEdge of item firstItem and the edge secondEdge of item secondItem. The magnitude 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 the new anchor will replace the old one.
firstItem and secondItem are automatically added to the layout if they are not part of the layout. This means that count() can increase with 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 behaviour 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.
See also addCornerAnchors() and addAnchors().
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.
Calling this convenience function with the following arguments
l->addAnchors(firstItem, secondItem, Qt::Horizontal)
is the same as
l->addAnchor(firstItem, Qt::AnchorLeft, secondItem, Qt::AnchorLeft); l->addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
Creates two anchors between firstItem and secondItem, where one is for the horizontal edge and another one for the vertical edge that the corners firstCorner and secondCorner specifies. The magnitude of the anchors is picked up from the style.
This is a convenience function, since anchoring corners can be expressed as anchoring two edges. For instance,
layout->addAnchor(layout, Qt::AnchorTop, b, Qt::AnchorTop); layout->addAnchor(layout, Qt::AnchorLeft, b, Qt::AnchorLeft);
has the same effect as
layout->addCornerAnchors(layout, Qt::TopLeft, b, Qt::TopLeft);
If there is already an anchor between the edge pairs, it will be replaced by the anchors that this function specifies.
firstItem and secondItem are automatically added to the layout if they are not part of the layout. This means that count() can increase with up to 2.
Returns the anchor between the anchor points defined by firstItem and firstEdge and secondItem and secondEdge. If there is no such anchor, the function will return 0.
Reimplemented from QGraphicsLayout::count().
Returns the default horizontal spacing for the anchor layout.
See also verticalSpacing() and setHorizontalSpacing().
Reimplemented from QGraphicsLayout::invalidate().
Reimplemented from QGraphicsLayout::itemAt().
Reimplemented from QGraphicsLayout::removeAt().
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.
See also itemAt() and count().
Reimplemented from QGraphicsLayoutItem::setGeometry().
Sets the default horizontal spacing for the anchor layout to spacing.
See also horizontalSpacing(), setVerticalSpacing(), and setSpacing().
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.
See also setHorizontalSpacing() and setVerticalSpacing().
Sets the default vertical spacing for the anchor layout to spacing.
See also verticalSpacing(), setHorizontalSpacing(), and setSpacing().
Reimplemented from QGraphicsLayoutItem::sizeHint().
Returns the default vertical spacing for the anchor layout.
See also horizontalSpacing() and setVerticalSpacing().
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.6.0 |