Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGraphicsAnchorLayout Class

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

Header:#include <QGraphicsAnchorLayout>
Since: Qt 4.6
Inherits:QGraphicsLayout

Public Functions

QGraphicsAnchorLayout(QGraphicsLayoutItem * parent = 0)
virtual~QGraphicsAnchorLayout()
QGraphicsAnchor *addAnchor(QGraphicsLayoutItem * firstItem, Qt::AnchorPoint firstEdge, QGraphicsLayoutItem * secondItem, Qt::AnchorPoint secondEdge)
voidaddAnchors(QGraphicsLayoutItem * firstItem, QGraphicsLayoutItem * secondItem, Qt::Orientations orientations = Qt::Horizontal | Qt::Vertical)
voidaddCornerAnchors(QGraphicsLayoutItem * firstItem, Qt::Corner firstCorner, QGraphicsLayoutItem * secondItem, Qt::Corner secondCorner)
QGraphicsAnchor *anchor(QGraphicsLayoutItem * firstItem, Qt::AnchorPoint firstEdge, QGraphicsLayoutItem * secondItem, Qt::AnchorPoint secondEdge)
qrealhorizontalSpacing() const
voidsetHorizontalSpacing(qreal spacing)
voidsetSpacing(qreal spacing)
voidsetVerticalSpacing(qreal spacing)
qrealverticalSpacing() const

Reimplemented Public Functions

virtual intcount() const
virtual voidinvalidate()
virtual QGraphicsLayoutItem *itemAt(int index) const
virtual voidremoveAt(int index)
virtual voidsetGeometry(const QRectF & geom)

Reimplemented Protected Functions

virtual QSizeFsizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const

Additional Inherited Members

Detailed Description

TheQGraphicsAnchorLayout 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 callingaddAnchor(),addAnchors() oraddCornerAnchors().

Existing anchors in the layout can be accessed with theanchor() function. Items that are anchored are automatically added to the layout, and if items are removed, all their anchors will be automatically removed.

Using an anchor layout to align simple colored widgets.

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 itema is anchored to the left edge of itemb and the bottom edge of itema is anchored to the top edge of itemb, with the result that itemb will be placed diagonally to the right and below itemb.

TheaddCornerAnchors() function provides a simpler way of anchoring the corners of two widgets than the two individual calls toaddAnchor() 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 theaddAnchors() function. As with the other functions for specifying anchors, it can also be used to anchor a widget to a layout.


Size Hints and Size Policies in an Anchor Layout

QGraphicsAnchorLayout respects each item's size hints and size policies. Note that there are some properties ofQSizePolicy that arenot respected.

Spacing within an Anchor Layout

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 theopposite 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 andPM_LayoutVerticalSpacing for vertical anchors.

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

Known issues

There are some features thatQGraphicsAnchorLayout 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:

See alsoQGraphicsLinearLayout,QGraphicsGridLayout, andQGraphicsLayout.

Member Function Documentation

QGraphicsAnchorLayout::QGraphicsAnchorLayout(QGraphicsLayoutItem * parent = 0)

Constructs aQGraphicsAnchorLayout instance.parent is passed toQGraphicsLayout's constructor.

[virtual]QGraphicsAnchorLayout::~QGraphicsAnchorLayout()

Destroys theQGraphicsAnchorLayout object.

QGraphicsAnchor * QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem * firstItem,Qt::AnchorPoint firstEdge,QGraphicsLayoutItem * secondItem,Qt::AnchorPoint secondEdge)

Creates an anchor between the edgefirstEdge of itemfirstItem and the edgesecondEdge of itemsecondItem. 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 the new anchor will replace the old one.

firstItem andsecondItem are automatically added to the layout if they are not part of the layout. This means thatcount() 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 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 usingQGraphicsAnchor::setSpacing() method.

Calling this function wherefirstItem orsecondItem are ancestors of the layout have undefined behaviour.

See alsoaddAnchors() andaddCornerAnchors().

void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem * firstItem,QGraphicsLayoutItem * secondItem,Qt::Orientations orientations = Qt::Horizontal | Qt::Vertical)

Anchors two or four edges offirstItem with the corresponding edges ofsecondItem, so thatfirstItem has the same size assecondItem in the dimensions specified byorientations.

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 alsoaddAnchor() andaddCornerAnchors().

void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem * firstItem,Qt::Corner firstCorner,QGraphicsLayoutItem * secondItem,Qt::Corner secondCorner)

Creates two anchors betweenfirstItem andsecondItem specified by the corners,firstCorner andsecondCorner, where one is for the horizontal edge and another one for the vertical edge.

This is a convenience function, since anchoring corners can be expressed as anchoring two edges. For instance:

layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);layout->addAnchor(a, Qt::AnchorLeft, layout, Qt::AnchorLeft);

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

layout->addCornerAnchors(a,Qt::TopLeftCorner, layout,Qt::TopLeftCorner);

If there is already an anchor between the edge pairs, it will be replaced by the anchors that this function specifies.

firstItem andsecondItem are automatically added to the layout if they are not part of the layout. This means thatcount() can increase by up to 2.

See alsoaddAnchor() andaddAnchors().

QGraphicsAnchor * QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem * firstItem,Qt::AnchorPoint firstEdge,QGraphicsLayoutItem * secondItem,Qt::AnchorPoint secondEdge)

Returns the anchor between the anchor points defined byfirstItem andfirstEdge andsecondItem andsecondEdge. If there is no such anchor, the function will return 0.

[virtual]int QGraphicsAnchorLayout::count() const

Reimplemented fromQGraphicsLayout::count().

qreal QGraphicsAnchorLayout::horizontalSpacing() const

Returns the default horizontal spacing for the anchor layout.

See alsoverticalSpacing() andsetHorizontalSpacing().

[virtual]void QGraphicsAnchorLayout::invalidate()

Reimplemented fromQGraphicsLayout::invalidate().

[virtual]QGraphicsLayoutItem * QGraphicsAnchorLayout::itemAt(int index) const

Reimplemented fromQGraphicsLayout::itemAt().

[virtual]void QGraphicsAnchorLayout::removeAt(int index)

Reimplemented fromQGraphicsLayout::removeAt().

Removes the layout item atindex 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 alsoitemAt() andcount().

[virtual]void QGraphicsAnchorLayout::setGeometry(constQRectF & geom)

Reimplemented fromQGraphicsLayoutItem::setGeometry().

void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing)

Sets the default horizontal spacing for the anchor layout tospacing.

See alsohorizontalSpacing(),setVerticalSpacing(), andsetSpacing().

void QGraphicsAnchorLayout::setSpacing(qreal spacing)

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

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 alsosetHorizontalSpacing() andsetVerticalSpacing().

void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing)

Sets the default vertical spacing for the anchor layout tospacing.

See alsoverticalSpacing(),setHorizontalSpacing(), andsetSpacing().

[virtual protected]QSizeF QGraphicsAnchorLayout::sizeHint(Qt::SizeHint which, constQSizeF & constraint = QSizeF()) const

Reimplemented fromQGraphicsLayoutItem::sizeHint().

qreal QGraphicsAnchorLayout::verticalSpacing() const

Returns the default vertical spacing for the anchor layout.

See alsohorizontalSpacing() andsetVerticalSpacing().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp