Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QGraphicsAnchorLayout Class

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.

Public Functions

QGraphicsAnchorLayout(QGraphicsLayoutItem * parent = 0)
QGraphicsLayout(QGraphicsLayoutItem * parent = 0)
QGraphicsLayoutItem(QGraphicsLayoutItem * parent = 0, bool isLayout = false)
virtual ~QGraphicsAnchorLayout()
~QGraphicsLayout()
virtual ~QGraphicsLayoutItem()
void activate()
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)
QRectF contentsRect() const
virtual int count() const = 0
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const
QRectF geometry() const
virtual void getContentsMargins(qreal * left, qreal * top, qreal * right, qreal * bottom) const
QGraphicsItem * graphicsItem() const
qreal horizontalSpacing() const
virtual void invalidate()
bool isActivated() const
bool isLayout() const
virtual QGraphicsLayoutItem * itemAt(int i) const = 0
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
virtual void removeAt(int index) = 0
void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
virtual void setGeometry(const QRectF & rect)
void setHorizontalSpacing(qreal spacing)
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)
void setSpacing(qreal spacing)
void setVerticalSpacing(qreal spacing)
QSizePolicy sizePolicy() const
virtual void updateGeometry()
qreal verticalSpacing() const
virtual void widgetEvent(QEvent * e)

Reimplemented Public Functions

virtual int count() const
virtual void invalidate()
virtual QGraphicsLayoutItem * itemAt(int index) const
virtual void removeAt(int index)
virtual void setGeometry(const QRectF & geom)

Protected Functions

void addChildLayoutItem(QGraphicsLayoutItem * layoutItem)
void setGraphicsItem(QGraphicsItem * item)
void setOwnedByLayout(bool ownership)
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const = 0

Reimplemented Protected Functions

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

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.

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 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.

The addCornerAnchors() function provides a simpler way of anchoring the corners of two widgets than the two individual calls to 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 addAnchors() 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 of QSizePolicy that are not 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 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.

Known issues

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

See also QGraphicsLinearLayout, QGraphicsGridLayout, and QGraphicsLayout.

Member Function Documentation

QGraphicsAnchorLayout::QGraphicsAnchorLayout(QGraphicsLayoutItem * parent = 0)

Constructs a QGraphicsAnchorLayout instance. parent is passed to QGraphicsLayout's constructor.

QGraphicsAnchorLayout::~QGraphicsAnchorLayout() [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 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 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 using QGraphicsAnchor::setSpacing() method.

Calling this function where firstItem or secondItem are ancestors of the layout have undefined behaviour.

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

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 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.

See also addAnchor() and addAnchors().

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

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.

int QGraphicsAnchorLayout::count() const [virtual]

Reimplemented from QGraphicsLayout::count().

qreal QGraphicsAnchorLayout::horizontalSpacing() const

Returns the default horizontal spacing for the anchor layout.

See also verticalSpacing() and setHorizontalSpacing().

void QGraphicsAnchorLayout::invalidate() [virtual]

Reimplemented from QGraphicsLayout::invalidate().

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

Reimplemented from QGraphicsLayout::itemAt().

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

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

void QGraphicsAnchorLayout::setGeometry(const QRectF & geom) [virtual]

Reimplemented from QGraphicsLayoutItem::setGeometry().

void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing)

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

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

void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing)

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

See also verticalSpacing(), setHorizontalSpacing(), and setSpacing().

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

Reimplemented from QGraphicsLayoutItem::sizeHint().

qreal QGraphicsAnchorLayout::verticalSpacing() const

Returns the default vertical spacing for the anchor layout.

See also horizontalSpacing() and setVerticalSpacing().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web