CopperSpice API  1.9.1
QGraphicsAnchorLayout Class Reference

The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics View. More...

Inheritance diagram for QGraphicsAnchorLayout:
QGraphicsLayout QGraphicsLayoutItem

Public Methods

 QGraphicsAnchorLayout (QGraphicsLayoutItem *parent=nullptr)
 
virtual ~QGraphicsAnchorLayout ()
 
QGraphicsAnchoraddAnchor (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)
 
QGraphicsAnchoranchor (QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
 
int count () const override
 
qreal horizontalSpacing () const
 
void invalidate () override
 
QGraphicsLayoutItemitemAt (int index) const override
 
void removeAt (int index) override
 
void setGeometry (const QRectF &rectF) override
 
void setHorizontalSpacing (qreal spacing)
 
void setSpacing (qreal spacing)
 
void setVerticalSpacing (qreal spacing)
 
qreal verticalSpacing () const
 
- Public Methods inherited from QGraphicsLayout
 QGraphicsLayout (QGraphicsLayoutItem *parent=nullptr)
 
 ~QGraphicsLayout ()
 
void activate ()
 
void getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const override
 
bool isActivated () const
 
void setContentsMargins (qreal left, qreal top, qreal right, qreal bottom)
 
void updateGeometry () override
 
virtual void widgetEvent (QEvent *event)
 
- Public Methods inherited from QGraphicsLayoutItem
 QGraphicsLayoutItem (QGraphicsLayoutItem *parent=nullptr, bool isLayout=false)
 
virtual ~QGraphicsLayoutItem ()
 
QRectF contentsRect () const
 
QSizeF effectiveSizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF ()) const
 
QRectF geometry () const
 
QGraphicsItemgraphicsItem () const
 
bool isLayout () const
 
qreal maximumHeight () const
 
QSizeF maximumSize () const
 
qreal maximumWidth () const
 
qreal minimumHeight () const
 
QSizeF minimumSize () const
 
qreal minimumWidth () const
 
bool ownedByLayout () const
 
QGraphicsLayoutItem * parentLayoutItem () const
 
qreal preferredHeight () const
 
QSizeF preferredSize () const
 
qreal preferredWidth () const
 
void setMaximumHeight (qreal height)
 
void setMaximumSize (const QSizeF &size)
 
void setMaximumSize (qreal w, qreal h)
 
void setMaximumWidth (qreal width)
 
void setMinimumHeight (qreal height)
 
void setMinimumSize (const QSizeF &size)
 
void setMinimumSize (qreal w, qreal h)
 
void setMinimumWidth (qreal width)
 
void setParentLayoutItem (QGraphicsLayoutItem *parent)
 
void setPreferredHeight (qreal height)
 
void setPreferredSize (const QSizeF &size)
 
void setPreferredSize (qreal w, qreal h)
 
void setPreferredWidth (qreal width)
 
void setSizePolicy (const QSizePolicy &policy)
 
void setSizePolicy (QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType=QSizePolicy::DefaultType)
 
QSizePolicy sizePolicy () const
 

Protected Methods

QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF ()) const override
 
- Protected Methods inherited from QGraphicsLayout
void addChildLayoutItem (QGraphicsLayoutItem *layoutItem)
 
- Protected Methods inherited from QGraphicsLayoutItem
void setGraphicsItem (QGraphicsItem *item)
 
void setOwnedByLayout (bool owner)
 

Friends

class QGraphicsAnchor
 

Additional Inherited Members

- Static Public Methods inherited from QGraphicsLayout
static bool instantInvalidatePropagation ()
 
static void setInstantInvalidatePropagation (bool enable)
 

Detailed Description

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.

Constructor & Destructor Documentation

QGraphicsAnchorLayout::QGraphicsAnchorLayout ( QGraphicsLayoutItem parent = nullptr)

Constructs a QGraphicsAnchorLayout instance. The parent object is passed to the QGraphicsLayout constructor.

QGraphicsAnchorLayout::~QGraphicsAnchorLayout ( )
virtual

Destroys the QGraphicsAnchorLayout object.

Method Documentation

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.

See also
addAnchors(), addCornerAnchors()
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.

layout->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
layout->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight);

This can also be achieved using the following line of code:

layout->addAnchors(b, c, Qt::Horizontal);
See also
addAnchor(), addCornerAnchors()
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.

// example A
layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
layout->addAnchor(a, Qt::AnchorLeft, layout, Qt::AnchorLeft);
// example B
layout->addCornerAnchors(a, Qt::TopLeftCorner, layout, Qt::TopLeftCorner);
See also
addAnchor(), addAnchors()
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.

int QGraphicsAnchorLayout::count ( ) const
overridevirtual
qreal QGraphicsAnchorLayout::horizontalSpacing ( ) const

Returns the default horizontal spacing for the anchor layout.

See also
verticalSpacing(), setHorizontalSpacing()
void QGraphicsAnchorLayout::invalidate ( )
overridevirtual

Reimplemented from QGraphicsLayout::invalidate()

QGraphicsLayoutItem * QGraphicsAnchorLayout::itemAt ( int  index) const
overridevirtual
void QGraphicsAnchorLayout::removeAt ( int  index)
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.

See also
itemAt(), count()

Implements QGraphicsLayout::removeAt()

void QGraphicsAnchorLayout::setGeometry ( const QRectF rectF)
overridevirtual
void QGraphicsAnchorLayout::setHorizontalSpacing ( qreal  spacing)

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

See also
horizontalSpacing(), setVerticalSpacing(), setSpacing()
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.

See also
setHorizontalSpacing(), setVerticalSpacing()
void QGraphicsAnchorLayout::setVerticalSpacing ( qreal  spacing)

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

See also
verticalSpacing(), setHorizontalSpacing(), setSpacing()
QSizeF QGraphicsAnchorLayout::sizeHint ( Qt::SizeHint  which,
const QSizeF constraint = QSizeF() 
) const
overrideprotectedvirtual
qreal QGraphicsAnchorLayout::verticalSpacing ( ) const

Returns the default vertical spacing for the anchor layout.

See also
horizontalSpacing(), setVerticalSpacing()