Qt 4.8
Public Functions | Protected Functions | Friends | List of all members
QGraphicsAnchorLayout Class Reference

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

#include <qgraphicsanchorlayout.h>

Inheritance diagram for QGraphicsAnchorLayout:
QGraphicsLayout QGraphicsLayoutItem

Public Functions

QGraphicsAnchoraddAnchor (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. More...
 
void 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. More...
 
void 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. More...
 
QGraphicsAnchoranchor (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. More...
 
int count () const
 Reimplemented Function More...
 
qreal horizontalSpacing () const
 Returns the default horizontal spacing for the anchor layout. More...
 
void invalidate ()
 Reimplemented Function More...
 
QGraphicsLayoutItemitemAt (int index) const
 Reimplemented Function More...
 
 QGraphicsAnchorLayout (QGraphicsLayoutItem *parent=0)
 Constructs a QGraphicsAnchorLayout instance. More...
 
void removeAt (int index)
 Removes the layout item at index without destroying it. More...
 
void setGeometry (const QRectF &rect)
 Reimplemented Function More...
 
void setHorizontalSpacing (qreal spacing)
 Sets the default horizontal spacing for the anchor layout to spacing. More...
 
void setSpacing (qreal spacing)
 Sets the default horizontal and the default vertical spacing for the anchor layout to spacing. More...
 
void setVerticalSpacing (qreal spacing)
 Sets the default vertical spacing for the anchor layout to spacing. More...
 
qreal verticalSpacing () const
 Returns the default vertical spacing for the anchor layout. More...
 
virtual ~QGraphicsAnchorLayout ()
 Destroys the QGraphicsAnchorLayout object. More...
 
- Public Functions inherited from QGraphicsLayout
void activate ()
 Activates the layout, causing all items in the layout to be immediately rearranged. More...
 
void getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const
 Reimplemented Function More...
 
bool isActivated () const
 Returns true if the layout is currently being activated; otherwise, returns false. More...
 
 QGraphicsLayout (QGraphicsLayoutItem *parent=0)
 Contructs a QGraphicsLayout object. More...
 
void setContentsMargins (qreal left, qreal top, qreal right, qreal bottom)
 Sets the contents margins to left, top, right and bottom. More...
 
virtual void updateGeometry ()
 Reimplemented Function More...
 
virtual void widgetEvent (QEvent *e)
 This virtual event handler receives all events for the managed widget. More...
 
 ~QGraphicsLayout ()
 Destroys the QGraphicsLayout object. More...
 
- Public Functions inherited from QGraphicsLayoutItem
QRectF contentsRect () const
 Returns the contents rect in local coordinates. More...
 
QSizeF effectiveSizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
 Returns the effective size hint for this QGraphicsLayoutItem. More...
 
QRectF geometry () const
 Returns the item's geometry (e. More...
 
QGraphicsItemgraphicsItem () const
 Returns the QGraphicsItem that this layout item represents. More...
 
bool isLayout () const
 Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges other QGraphicsLayoutItem objects); otherwise returns false. More...
 
qreal maximumHeight () const
 Returns the maximum height. More...
 
QSizeF maximumSize () const
 Returns the maximum size. More...
 
qreal maximumWidth () const
 Returns the maximum width. More...
 
qreal minimumHeight () const
 Returns the minimum height. More...
 
QSizeF minimumSize () const
 Returns the minimum size. More...
 
qreal minimumWidth () const
 Returns the minimum width. More...
 
bool ownedByLayout () const
 Returns whether a layout should delete this item in its destructor. More...
 
QGraphicsLayoutItemparentLayoutItem () const
 Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not inherit from QGraphicsLayoutItem (QGraphicsLayoutItem is often used through multiple inheritance with QObject-derived classes). More...
 
qreal preferredHeight () const
 Returns the preferred height. More...
 
QSizeF preferredSize () const
 Returns the preferred size. More...
 
qreal preferredWidth () const
 Returns the preferred width. More...
 
 QGraphicsLayoutItem (QGraphicsLayoutItem *parent=0, bool isLayout=false)
 Constructs the QGraphicsLayoutItem object. More...
 
void setMaximumHeight (qreal height)
 Sets the maximum height to height. More...
 
void setMaximumSize (const QSizeF &size)
 Sets the maximum size to size. More...
 
void setMaximumSize (qreal w, qreal h)
 This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)). More...
 
void setMaximumWidth (qreal width)
 Sets the maximum width to width. More...
 
void setMinimumHeight (qreal height)
 Sets the minimum height to height. More...
 
void setMinimumSize (const QSizeF &size)
 Sets the minimum size to size. More...
 
void setMinimumSize (qreal w, qreal h)
 This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)). More...
 
void setMinimumWidth (qreal width)
 Sets the minimum width to width. More...
 
void setParentLayoutItem (QGraphicsLayoutItem *parent)
 Sets the parent of this QGraphicsLayoutItem to parent. More...
 
void setPreferredHeight (qreal height)
 Sets the preferred height to height. More...
 
void setPreferredSize (const QSizeF &size)
 Sets the preferred size to size. More...
 
void setPreferredSize (qreal w, qreal h)
 This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)). More...
 
void setPreferredWidth (qreal width)
 Sets the preferred width to width. More...
 
void setSizePolicy (const QSizePolicy &policy)
 Sets the size policy to policy. More...
 
void setSizePolicy (QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType=QSizePolicy::DefaultType)
 This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)). More...
 
QSizePolicy sizePolicy () const
 Returns the current size policy. More...
 
virtual ~QGraphicsLayoutItem ()
 Destroys the QGraphicsLayoutItem object. More...
 

Protected Functions

QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
 Reimplemented Function More...
 
- Protected Functions inherited from QGraphicsLayout
void addChildLayoutItem (QGraphicsLayoutItem *layoutItem)
 This function is a convenience function provided for custom layouts, and will go through all items in the layout and reparent their graphics items to the closest QGraphicsWidget ancestor of the layout. More...
 
 QGraphicsLayout (QGraphicsLayoutPrivate &, QGraphicsLayoutItem *)
 
- Protected Functions inherited from QGraphicsLayoutItem
 QGraphicsLayoutItem (QGraphicsLayoutItemPrivate &dd)
 
void setGraphicsItem (QGraphicsItem *item)
 If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of QGraphicsLayout it should set this value. More...
 
void setOwnedByLayout (bool ownedByLayout)
 Sets whether a layout should delete this item in its destructor or not. More...
 

Friends

class QGraphicsAnchor
 

Additional Inherited Members

- Static Public Functions inherited from QGraphicsLayout
static bool instantInvalidatePropagation ()
 
static void setInstantInvalidatePropagation (bool enable)
 
- Protected Variables inherited from QGraphicsLayoutItem
QScopedPointer< QGraphicsLayoutItemPrivated_ptr
 

Detailed Description

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

Since
4.6

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.

{class="float-left"}

simpleanchorlayout-example.png
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:

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:

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 Known issues{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: QStyle::PM_LayoutHorizontalSpacing for horizontal anchors and QStyle::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, QGraphicsLayout

Definition at line 82 of file qgraphicsanchorlayout.h.

Constructors and Destructors

◆ QGraphicsAnchorLayout()

QGraphicsAnchorLayout::QGraphicsAnchorLayout ( QGraphicsLayoutItem parent = 0)

Constructs a QGraphicsAnchorLayout instance.

parent is passed to QGraphicsLayout's constructor.

Definition at line 227 of file qgraphicsanchorlayout.cpp.

229 {
231  d->createLayoutEdges();
232 }
double d
Definition: qnumeric_p.h:62
QGraphicsLayout(QGraphicsLayoutItem *parent=0)
Contructs a QGraphicsLayout object.
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...
QGraphicsAnchorLayout private methods and attributes.

◆ ~QGraphicsAnchorLayout()

QGraphicsAnchorLayout::~QGraphicsAnchorLayout ( )
virtual

Destroys the QGraphicsAnchorLayout object.

Definition at line 237 of file qgraphicsanchorlayout.cpp.

238 {
240 
241  for (int i = count() - 1; i >= 0; --i) {
242  QGraphicsLayoutItem *item = d->items.at(i);
243  removeAt(i);
244  if (item) {
245  if (item->ownedByLayout())
246  delete item;
247  }
248  }
249 
250  d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Horizontal);
251  d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Vertical);
252  d->deleteLayoutEdges();
253 
254  Q_ASSERT(d->itemCenterConstraints[0].isEmpty());
255  Q_ASSERT(d->itemCenterConstraints[1].isEmpty());
256  Q_ASSERT(d->items.isEmpty());
257  Q_ASSERT(d->m_vertexList.isEmpty());
258 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
bool ownedByLayout() const
Returns whether a layout should delete this item in its destructor.
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...
int count() const
Reimplemented Function
void removeAt(int index)
Removes the layout item at index without destroying it.

Functions

◆ addAnchor()

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(), addCornerAnchors()

Definition at line 283 of file qgraphicsanchorlayout.cpp.

Referenced by addAnchors().

285 {
287  QGraphicsAnchor *a = d->addAnchor(firstItem, firstEdge, secondItem, secondEdge);
288  invalidate();
289  return a;
290 }
double d
Definition: qnumeric_p.h:62
The QGraphicsAnchor class represents an anchor between two items in a QGraphicsAnchorLayout.
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ addAnchors()

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:

layout->addAnchors(b, c, Qt::Horizontal);
See also
addAnchor(), addCornerAnchors()

Definition at line 362 of file qgraphicsanchorlayout.cpp.

365 {
366  bool ok = true;
367  if (orientations & Qt::Horizontal) {
368  // Currently, if the first is ok, then the rest of the calls should be ok
369  ok = addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft) != 0;
370  if (ok)
371  addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
372  }
373  if (orientations & Qt::Vertical && ok) {
374  addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop);
375  addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom);
376  }
377 }
QGraphicsAnchor * 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 second...

◆ 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:

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

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(), addAnchors()

Definition at line 326 of file qgraphicsanchorlayout.cpp.

330 {
332 
333  // Horizontal anchor
334  Qt::AnchorPoint firstEdge = (firstCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft);
335  Qt::AnchorPoint secondEdge = (secondCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft);
336  if (d->addAnchor(firstItem, firstEdge, secondItem, secondEdge)) {
337  // Vertical anchor
338  firstEdge = (firstCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop);
339  secondEdge = (secondCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop);
340  d->addAnchor(firstItem, firstEdge, secondItem, secondEdge);
341 
342  invalidate();
343  }
344 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
AnchorPoint
Definition: qnamespace.h:1586
void invalidate()
Reimplemented Function
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ anchor()

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.

Definition at line 297 of file qgraphicsanchorlayout.cpp.

299 {
301  return d->getAnchor(firstItem, firstEdge, secondItem, secondEdge);
302 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ count()

int QGraphicsAnchorLayout::count ( ) const
virtual

Reimplemented Function

Implements QGraphicsLayout.

Definition at line 488 of file qgraphicsanchorlayout.cpp.

Referenced by ~QGraphicsAnchorLayout().

489 {
490  Q_D(const QGraphicsAnchorLayout);
491  return d->items.size();
492 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ horizontalSpacing()

qreal QGraphicsAnchorLayout::horizontalSpacing ( ) const

Returns the default horizontal spacing for the anchor layout.

See also
verticalSpacing(), setHorizontalSpacing()

Definition at line 429 of file qgraphicsanchorlayout.cpp.

430 {
431  Q_D(const QGraphicsAnchorLayout);
432  return d->styleInfo().defaultSpacing(Qt::Horizontal);
433 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ invalidate()

void QGraphicsAnchorLayout::invalidate ( )
virtual

Reimplemented Function

Reimplemented from QGraphicsLayout.

Definition at line 506 of file qgraphicsanchorlayout.cpp.

Referenced by addAnchor(), addCornerAnchors(), removeAt(), setHorizontalSpacing(), setSpacing(), and setVerticalSpacing().

507 {
510  d->calculateGraphCacheDirty = true;
511  d->styleInfoDirty = true;
512 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void invalidate()
Clears any cached geometry and size hint information in the layout, and posts a LayoutRequest event t...
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ itemAt()

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

Reimplemented Function

Implements QGraphicsLayout.

Definition at line 497 of file qgraphicsanchorlayout.cpp.

498 {
499  Q_D(const QGraphicsAnchorLayout);
500  return d->items.value(index);
501 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...
quint16 index

◆ removeAt()

void QGraphicsAnchorLayout::removeAt ( int  index)
virtual

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.

Definition at line 467 of file qgraphicsanchorlayout.cpp.

Referenced by ~QGraphicsAnchorLayout().

468 {
470  QGraphicsLayoutItem *item = d->items.value(index);
471 
472  if (!item)
473  return;
474 
475  // Removing an item affects both horizontal and vertical graphs
476  d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Horizontal);
477  d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Vertical);
478  d->removeAnchors(item);
479  d->items.remove(index);
480 
481  item->setParentLayoutItem(0);
482  invalidate();
483 }
double d
Definition: qnumeric_p.h:62
void setParentLayoutItem(QGraphicsLayoutItem *parent)
Sets the parent of this QGraphicsLayoutItem to parent.
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...
quint16 index

◆ setGeometry()

void QGraphicsAnchorLayout::setGeometry ( const QRectF rect)
virtual

Reimplemented Function

Reimplemented from QGraphicsLayoutItem.

Definition at line 449 of file qgraphicsanchorlayout.cpp.

450 {
452 
454  d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Horizontal);
455  d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Vertical);
456  d->setItemsGeometries(geom);
457 }
double d
Definition: qnumeric_p.h:62
virtual void setGeometry(const QRectF &rect)
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordi...
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ setHorizontalSpacing()

void QGraphicsAnchorLayout::setHorizontalSpacing ( qreal  spacing)

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

See also
horizontalSpacing(), setVerticalSpacing(), setSpacing()

Definition at line 384 of file qgraphicsanchorlayout.cpp.

385 {
387 
388  d->spacings[0] = spacing;
389  invalidate();
390 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

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

Definition at line 416 of file qgraphicsanchorlayout.cpp.

417 {
419 
420  d->spacings[0] = d->spacings[1] = spacing;
421  invalidate();
422 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ setVerticalSpacing()

void QGraphicsAnchorLayout::setVerticalSpacing ( qreal  spacing)

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

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

Definition at line 397 of file qgraphicsanchorlayout.cpp.

398 {
400 
401  d->spacings[1] = spacing;
402  invalidate();
403 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

◆ sizeHint()

QSizeF QGraphicsAnchorLayout::sizeHint ( Qt::SizeHint  which,
const QSizeF constraint = QSizeF() 
) const
protectedvirtual

Reimplemented Function

Implements QGraphicsLayoutItem.

Definition at line 517 of file qgraphicsanchorlayout.cpp.

518 {
519  Q_UNUSED(constraint);
520  Q_D(const QGraphicsAnchorLayout);
521 
522  // Some setup calculations are delayed until the information is
523  // actually needed, avoiding unnecessary recalculations when
524  // adding multiple anchors.
525 
526  // sizeHint() / effectiveSizeHint() already have a cache
527  // mechanism, using invalidate() to force recalculation. However
528  // sizeHint() is called three times after invalidation (for max,
529  // min and pref), but we just need do our setup once.
530 
531  const_cast<QGraphicsAnchorLayoutPrivate *>(d)->calculateGraphs();
532 
533  // ### apply constraint!
534  QSizeF engineSizeHint(
535  d->sizeHints[QGraphicsAnchorLayoutPrivate::Horizontal][which],
536  d->sizeHints[QGraphicsAnchorLayoutPrivate::Vertical][which]);
537 
538  qreal left, top, right, bottom;
539  getContentsMargins(&left, &top, &right, &bottom);
540 
541  return engineSizeHint + QSizeF(left + right, top + bottom);
542 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
Reimplemented Function
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QGraphicsAnchorLayout private methods and attributes.

◆ verticalSpacing()

qreal QGraphicsAnchorLayout::verticalSpacing ( ) const

Returns the default vertical spacing for the anchor layout.

See also
horizontalSpacing(), setVerticalSpacing()

Definition at line 440 of file qgraphicsanchorlayout.cpp.

441 {
442  Q_D(const QGraphicsAnchorLayout);
443  return d->styleInfo().defaultSpacing(Qt::Vertical);
444 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...

Friends and Related Functions

◆ QGraphicsAnchor

friend class QGraphicsAnchor
friend

Definition at line 119 of file qgraphicsanchorlayout.h.


The documentation for this class was generated from the following files: