Qt 4.8
Public Functions | Protected Functions | Protected Variables | Private Functions | Friends | List of all members
QGraphicsLayoutItem Class Referenceabstract

The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts. More...

#include <qgraphicslayoutitem.h>

Inheritance diagram for QGraphicsLayoutItem:
QDeclarativeLayoutItem QGraphicsLayout QGraphicsWidget QGraphicsAnchorLayout QGraphicsGridLayout QGraphicsLinearLayout QGraphicsProxyWidget

Public Functions

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...
 
virtual void getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const
 This virtual function provides the left, top, right and bottom contents margins for this QGraphicsLayoutItem. 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...
 
virtual void setGeometry (const QRectF &rect)
 This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordinates (e. 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 void updateGeometry ()
 This virtual function discards any cached size hint information. More...
 
virtual ~QGraphicsLayoutItem ()
 Destroys the QGraphicsLayoutItem object. More...
 

Protected Functions

 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...
 
virtual QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const =0
 This pure virtual function returns the size hint for which of the QGraphicsLayoutItem, using the width or height of constraint to constrain the output. More...
 

Protected Variables

QScopedPointer< QGraphicsLayoutItemPrivated_ptr
 

Private Functions

QSizeFeffectiveSizeHints (const QSizeF &constraint) const
 

Friends

class QGraphicsLayout
 

Detailed Description

The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.

Since
4.4

QGraphicsLayoutItem is an abstract class that defines a set of virtual functions describing sizes, size policies, and size hints for any object arranged by QGraphicsLayout. The API contains functions relevant for both the item itself and for the user of the item as most of QGraphicsLayoutItem's functions are also part of the subclass' public API.

In most cases, existing layout-aware classes such as QGraphicsWidget and QGraphicsLayout already provide the functionality you require. However, subclassing these classes will enable you to create both graphical elements that work well with layouts (QGraphicsWidget) or custom layouts (QGraphicsLayout).

Subclassing QGraphicsLayoutItem

If you create a subclass of QGraphicsLayoutItem and reimplement its virtual functions, you will enable the layout to resize and position your item along with other QGraphicsLayoutItems including QGraphicsWidget and QGraphicsLayout.

You can start by reimplementing important functions: the protected sizeHint() function, as well as the public setGeometry() function. If you want your items to be aware of immediate geometry changes, you can also reimplement updateGeometry().

The geometry, size hint, and size policy affect the item's size and position. Calling setGeometry() will always resize and reposition the item immediately. Normally, this function is called by QGraphicsLayout after the layout has been activated, but it can also be called by the item's user at any time.

The sizeHint() function returns the item' minimum, preferred and maximum size hints. You can override these properties by calling setMinimumSize(), setPreferredSize() or setMaximumSize(). You can also use functions such as setMinimumWidth() or setMaximumHeight() to set only the width or height component if desired.

The effectiveSizeHint() function, on the other hand, returns a size hint for any given Qt::SizeHint, and guarantees that the returned size is bound to the minimum and maximum sizes and size hints. You can set the item's vertical and horizontal size policy by calling setSizePolicy(). The sizePolicy property is used by the layout system to describe how this item prefers to grow or shrink.

Nesting QGraphicsLayoutItems

QGraphicsLayoutItems can be nested within other QGraphicsLayoutItems, similar to layouts that can contain sublayouts. This is done either by passing a QGraphicsLayoutItem pointer to QGraphicsLayoutItem's protected constructor, or by calling setParentLayoutItem(). The parentLayoutItem() function returns a pointer to the item's layoutItem parent. If the item's parent is 0 or if the parent does not inherit from QGraphicsItem, the parentLayoutItem() function then returns 0. isLayout() returns true if the QGraphicsLayoutItem subclass is itself a layout, or false otherwise.

Qt uses QGraphicsLayoutItem to provide layout functionality in the Graphics View Framework, but in the future its use may spread throughout Qt itself.

See also
QGraphicsWidget, QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout

Definition at line 59 of file qgraphicslayoutitem.h.

Constructors and Destructors

◆ QGraphicsLayoutItem() [1/2]

QGraphicsLayoutItem::QGraphicsLayoutItem ( QGraphicsLayoutItem parent = 0,
bool  isLayout = false 
)

Constructs the QGraphicsLayoutItem object.

parent becomes the object's parent. If isLayout is true the item is a layout, otherwise isLayout is false.

Definition at line 473 of file qgraphicslayoutitem.cpp.

475 {
477  d->init();
479  d->q_ptr = this;
480 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
#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 isLayout() const
Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges o...

◆ ~QGraphicsLayoutItem()

QGraphicsLayoutItem::~QGraphicsLayoutItem ( )
virtual

Destroys the QGraphicsLayoutItem object.

Definition at line 496 of file qgraphicslayoutitem.cpp.

497 {
499  if (parentLI && parentLI->isLayout()) {
500  QGraphicsLayout *lay = static_cast<QGraphicsLayout*>(parentLI);
501  // this is not optimal
502  for (int i = lay->count() - 1; i >= 0; --i) {
503  if (lay->itemAt(i) == this) {
504  lay->removeAt(i);
505  break;
506  }
507  }
508  }
509 }
virtual void removeAt(int index)=0
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to remove the item ...
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
bool isLayout() const
Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges o...
virtual int count() const =0
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return the numbe...
QGraphicsLayoutItem * parentLayoutItem() const
Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not...
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
virtual QGraphicsLayoutItem * itemAt(int i) const =0
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return a pointer...

◆ QGraphicsLayoutItem() [2/2]

QGraphicsLayoutItem::QGraphicsLayoutItem ( QGraphicsLayoutItemPrivate dd)
protected
Warning
This function is not part of the public interface.

Definition at line 485 of file qgraphicslayoutitem.cpp.

486  : d_ptr(&dd)
487 {
489  d->init();
490  d->q_ptr = this;
491 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...

Functions

◆ contentsRect()

QRectF QGraphicsLayoutItem::contentsRect ( ) const

Returns the contents rect in local coordinates.

The contents rect defines the subrectangle used by an associated layout when arranging subitems. This function is a convenience function that adjusts the item's geometry() by its contents margins. Note that getContentsMargins() is a virtual function that you can reimplement to return the item's contents margins.

See also
getContentsMargins(), geometry()

Definition at line 890 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayout::activate(), and QGraphicsLayout::widgetEvent().

891 {
892  qreal left, top, right, bottom;
893  getContentsMargins(&left, &top, &right, &bottom);
894  return QRectF(QPointF(), geometry().size()).adjusted(+left, +top, -right, -bottom);
895 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QRectF geometry() const
Returns the item&#39;s geometry (e.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
This virtual function provides the left, top, right and bottom contents margins for this QGraphicsLay...
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ effectiveSizeHint()

QSizeF QGraphicsLayoutItem::effectiveSizeHint ( Qt::SizeHint  which,
const QSizeF constraint = QSizeF() 
) const

Returns the effective size hint for this QGraphicsLayoutItem.

which is the size hint in question. constraint is an optional argument that defines a special constrain when calculating the effective size hint. By default, constraint is QSizeF(-1, -1), which means there is no constraint to the size hint.

If you want to specify the widget's size hint for a given width or height, you can provide the fixed dimension in constraint. This is useful for widgets that can grow only either vertically or horizontally, and need to set either their width or their height to a special value.

For example, a text paragraph item fit into a column width of 200 may grow vertically. You can pass QSizeF(200, -1) as a constraint to get a suitable minimum, preferred and maximum height).

You can adjust the effective size hint by reimplementing sizeHint() in a QGraphicsLayoutItem subclass, or by calling one of the following functions: setMinimumSize(), setPreferredSize, or setMaximumSize() (or a combination of both).

This function caches each of the size hints and guarantees that sizeHint() will be called only once for each value of which - unless constraint is not specified and updateGeometry() has been called.

See also
sizeHint()

Definition at line 925 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsWidget::adjustSize(), QGridLayoutItem::effectiveMaxSize(), maximumSize(), minimumHeightForWidth(), minimumSize(), preferredSize(), setGeometry(), QGraphicsWidget::setGeometry(), QGraphicsAnchorLayoutPrivate::setItemsGeometries(), and QGridLayoutItem::sizeHint().

926 {
927  Q_D(const QGraphicsLayoutItem);
928 
929  if (!d->userSizeHints && constraint.isValid())
930  return constraint;
931 
932  // ### should respect size policy???
933  return d_ptr->effectiveSizeHints(constraint)[which];
934 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
QSizeF * effectiveSizeHints(const QSizeF &constraint) const
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:281
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...

◆ effectiveSizeHints()

QSizeF* QGraphicsLayoutItem::effectiveSizeHints ( const QSizeF constraint) const
private

◆ geometry()

QRectF QGraphicsLayoutItem::geometry ( ) const

Returns the item's geometry (e.

g., position and size) as a QRectF. This function is equivalent to QRectF(pos(), size()).

See also
setGeometry()

Definition at line 853 of file qgraphicslayoutitem.cpp.

Referenced by contentsRect(), QGraphicsLinearLayout::setGeometry(), QGraphicsGridLayout::setGeometry(), QGraphicsWidget::windowFrameGeometry(), and QGraphicsWidget::~QGraphicsWidget().

854 {
855  Q_D(const QGraphicsLayoutItem);
856  return d->geom;
857 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...

◆ getContentsMargins()

void QGraphicsLayoutItem::getContentsMargins ( qreal left,
qreal top,
qreal right,
qreal bottom 
) const
virtual

This virtual function provides the left, top, right and bottom contents margins for this QGraphicsLayoutItem.

The default implementation assumes all contents margins are 0. The parameters point to values stored in qreals. If any of the pointers is 0, that value will not be updated.

See also
QGraphicsWidget::setContentsMargins()

Reimplemented in QGraphicsWidget, and QGraphicsLayout.

Definition at line 867 of file qgraphicslayoutitem.cpp.

Referenced by contentsRect(), and QGraphicsWidget::rect().

868 {
869  if (left)
870  *left = 0;
871  if (top)
872  *top = 0;
873  if (right)
874  *right = 0;
875  if (bottom)
876  *bottom = 0;
877 }
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ graphicsItem()

QGraphicsItem * QGraphicsLayoutItem::graphicsItem ( ) const

Returns the QGraphicsItem that this layout item represents.

For QGraphicsWidget it will return itself. For custom items it can return an aggregated value.

See also
setGraphicsItem()

Definition at line 1039 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayoutPrivate::addChildLayoutItem(), QGraphicsLayoutItemPrivate::parentItem(), QGraphicsLayout::QGraphicsLayout(), QGraphicsLayoutPrivate::reparentChildItems(), QGraphicsAnchorLayoutPrivate::styleInfo(), and AnchorVertex::toString().

1040 {
1041  return d_func()->graphicsItem;
1042 }

◆ isLayout()

bool QGraphicsLayoutItem::isLayout ( ) const

◆ maximumHeight()

qreal QGraphicsLayoutItem::maximumHeight ( ) const
inline

Returns the maximum height.

See also
setMaximumHeight(), setMaximumSize(), maximumSize()

Definition at line 146 of file qgraphicslayoutitem.h.

QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
qreal height() const
Returns the height.
Definition: qsize.h:287

◆ maximumSize()

QSizeF QGraphicsLayoutItem::maximumSize ( ) const

Returns the maximum size.

See also
setMaximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, sizeHint()

Definition at line 723 of file qgraphicslayoutitem.cpp.

724 {
726 }
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.

◆ maximumWidth()

qreal QGraphicsLayoutItem::maximumWidth ( ) const
inline

Returns the maximum width.

See also
setMaximumWidth(), setMaximumSize(), maximumSize()

Definition at line 144 of file qgraphicslayoutitem.h.

QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
qreal width() const
Returns the width.
Definition: qsize.h:284

◆ minimumHeight()

qreal QGraphicsLayoutItem::minimumHeight ( ) const
inline

Returns the minimum height.

See also
setMinimumHeight(), setMinimumSize(), minimumSize()

Definition at line 136 of file qgraphicslayoutitem.h.

QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
qreal height() const
Returns the height.
Definition: qsize.h:287

◆ minimumSize()

QSizeF QGraphicsLayoutItem::minimumSize ( ) const

Returns the minimum size.

See also
setMinimumSize(), preferredSize(), maximumSize(), Qt::MinimumSize, sizeHint()

Definition at line 609 of file qgraphicslayoutitem.cpp.

610 {
612 }
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.

◆ minimumWidth()

qreal QGraphicsLayoutItem::minimumWidth ( ) const
inline

Returns the minimum width.

See also
setMinimumWidth(), setMinimumSize(), minimumSize()

Definition at line 134 of file qgraphicslayoutitem.h.

QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
qreal width() const
Returns the width.
Definition: qsize.h:284

◆ ownedByLayout()

bool QGraphicsLayoutItem::ownedByLayout ( ) const

Returns whether a layout should delete this item in its destructor.

Since
4.6

If its true, then the layout will delete it. If its false, then it is assumed that another object has the ownership of it, and the layout won't delete this item.

If the item inherits both QGraphicsItem and QGraphicsLayoutItem (such as QGraphicsWidget does) the item is really part of two ownership hierarchies. This property informs what the layout should do with its child items when it is destructed. In the case of QGraphicsWidget, it is preferred that when the layout is deleted it won't delete its children (since they are also part of the graphics item hierarchy).

By default this value is initialized to false in QGraphicsLayoutItem, but it is overridden by QGraphicsLayout to return true. This is because QGraphicsLayout is not normally part of the QGraphicsItem hierarchy, so the parent layout should delete it. Subclasses might override this default behaviour by calling setOwnedByLayout(true).

See also
setOwnedByLayout()

Definition at line 1013 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsAnchorLayout::~QGraphicsAnchorLayout(), QGraphicsGridLayout::~QGraphicsGridLayout(), and QGraphicsLinearLayout::~QGraphicsLinearLayout().

1014 {
1015  return d_func()->ownedByLayout;
1016 }

◆ parentLayoutItem()

QGraphicsLayoutItem * QGraphicsLayoutItem::parentLayoutItem ( ) const

◆ preferredHeight()

qreal QGraphicsLayoutItem::preferredHeight ( ) const
inline

Returns the preferred height.

See also
setPreferredHeight(), setPreferredSize(), preferredSize()

Definition at line 141 of file qgraphicslayoutitem.h.

QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
qreal height() const
Returns the height.
Definition: qsize.h:287

◆ preferredSize()

QSizeF QGraphicsLayoutItem::preferredSize ( ) const

Returns the preferred size.

See also
setPreferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, sizeHint()

Definition at line 666 of file qgraphicslayoutitem.cpp.

667 {
669 }
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.

◆ preferredWidth()

qreal QGraphicsLayoutItem::preferredWidth ( ) const
inline

Returns the preferred width.

See also
setPreferredWidth(), setPreferredSize(), preferredSize()

Definition at line 139 of file qgraphicslayoutitem.h.

QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
qreal width() const
Returns the width.
Definition: qsize.h:284

◆ setGeometry()

void QGraphicsLayoutItem::setGeometry ( const QRectF rect)
virtual

This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordinates (e.

g., the top-left corner of rect is equivalent to the item's position in parent coordinates).

You must reimplement this function in a subclass of QGraphicsLayoutItem to receive geometry updates. The layout will call this function when it does a rearrangement.

If rect is outside of the bounds of minimumSize and maximumSize, it will be adjusted to its closest size so that it is within the legal bounds.

See also
geometry()

Reimplemented in QGraphicsGridLayout, QGraphicsWidget, QGraphicsAnchorLayout, QGraphicsLinearLayout, QDeclarativeLayoutItem, and QGraphicsProxyWidget.

Definition at line 834 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayout::activate(), QGraphicsLinearLayout::addStretch(), QGraphicsWidget::resize(), QGraphicsLinearLayout::setGeometry(), QGraphicsAnchorLayout::setGeometry(), QGraphicsWidget::setGeometry(), QGraphicsGridLayout::setGeometry(), QGridLayoutItem::setGeometry(), QGraphicsAnchorLayoutPrivate::setItemsGeometries(), and QGraphicsLayout::widgetEvent().

835 {
837  QSizeF effectiveSize = rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize))
839  d->geom = QRectF(rect.topLeft(), effectiveSize);
840 }
double d
Definition: qnumeric_p.h:62
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
#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
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
QSizeF boundedTo(const QSizeF &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:350
QSizeF expandedTo(const QSizeF &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:345
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713

◆ setGraphicsItem()

void QGraphicsLayoutItem::setGraphicsItem ( QGraphicsItem item)
protected

If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of QGraphicsLayout it should set this value.

Note that if you delete item and not delete the layout item, you are responsible of calling setGraphicsItem(0) in order to avoid having a dangling pointer.

See also
graphicsItem()

Definition at line 1054 of file qgraphicslayoutitem.cpp.

Referenced by QDeclarativeLayoutItem::QDeclarativeLayoutItem().

1055 {
1056  d_func()->graphicsItem = item;
1057 }

◆ setMaximumHeight()

void QGraphicsLayoutItem::setMaximumHeight ( qreal  height)

Sets the maximum height to height.

See also
maximumHeight(), setMaximumSize(), maximumSize()

Definition at line 743 of file qgraphicslayoutitem.cpp.

744 {
746 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSizeComponent(Qt::SizeHint which, SizeComponent component, qreal value)
Sets the width of the user size hint which to width.

◆ setMaximumSize() [1/2]

void QGraphicsLayoutItem::setMaximumSize ( const QSizeF size)

Sets the maximum size to size.

This property overrides sizeHint() for Qt::MaximumSize and ensures that effectiveSizeHint() will never return a size larger than size. In order to unset the maximum size, use an invalid size.

See also
maximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, sizeHint()

Definition at line 700 of file qgraphicslayoutitem.cpp.

701 {
702  d_ptr->setSize(Qt::MaximumSize, size);
703 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSize(Qt::SizeHint which, const QSizeF &size)
Sets the user size hint which to size.

◆ setMaximumSize() [2/2]

void QGraphicsLayoutItem::setMaximumSize ( qreal  w,
qreal  h 
)
inline

This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)).

See also
maximumSize(), setMinimumSize(), setPreferredSize(), sizeHint()

Definition at line 131 of file qgraphicslayoutitem.h.

132 { setMaximumSize(QSizeF(aw, ah)); }
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setMaximumSize(const QSizeF &size)
Sets the maximum size to size.

◆ setMaximumWidth()

void QGraphicsLayoutItem::setMaximumWidth ( qreal  width)

Sets the maximum width to width.

See also
maximumWidth(), setMaximumSize(), maximumSize()

Definition at line 733 of file qgraphicslayoutitem.cpp.

734 {
736 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSizeComponent(Qt::SizeHint which, SizeComponent component, qreal value)
Sets the width of the user size hint which to width.

◆ setMinimumHeight()

void QGraphicsLayoutItem::setMinimumHeight ( qreal  height)

Sets the minimum height to height.

See also
minimumHeight(), setMinimumSize(), minimumSize()

Definition at line 629 of file qgraphicslayoutitem.cpp.

630 {
632 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSizeComponent(Qt::SizeHint which, SizeComponent component, qreal value)
Sets the width of the user size hint which to width.

◆ setMinimumSize() [1/2]

void QGraphicsLayoutItem::setMinimumSize ( const QSizeF size)

Sets the minimum size to size.

This property overrides sizeHint() for Qt::MinimumSize and ensures that effectiveSizeHint() will never return a size smaller than size. In order to unset the minimum size, use an invalid size.

See also
minimumSize(), maximumSize(), preferredSize(), Qt::MinimumSize, sizeHint(), setMinimumWidth(), setMinimumHeight()

Definition at line 586 of file qgraphicslayoutitem.cpp.

587 {
588  d_ptr->setSize(Qt::MinimumSize, size);
589 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSize(Qt::SizeHint which, const QSizeF &size)
Sets the user size hint which to size.

◆ setMinimumSize() [2/2]

void QGraphicsLayoutItem::setMinimumSize ( qreal  w,
qreal  h 
)
inline

This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)).

See also
minimumSize(), setMaximumSize(), setPreferredSize(), sizeHint()

Definition at line 127 of file qgraphicslayoutitem.h.

128 { setMinimumSize(QSizeF(aw, ah)); }
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setMinimumSize(const QSizeF &size)
Sets the minimum size to size.

◆ setMinimumWidth()

void QGraphicsLayoutItem::setMinimumWidth ( qreal  width)

Sets the minimum width to width.

See also
minimumWidth(), setMinimumSize(), minimumSize()

Definition at line 619 of file qgraphicslayoutitem.cpp.

620 {
622 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSizeComponent(Qt::SizeHint which, SizeComponent component, qreal value)
Sets the width of the user size hint which to width.

◆ setOwnedByLayout()

void QGraphicsLayoutItem::setOwnedByLayout ( bool  ownership)
protected

Sets whether a layout should delete this item in its destructor or not.

Since
4.6

ownership must be true to in order for the layout to delete it.

See also
ownedByLayout()

Definition at line 1027 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayout::QGraphicsLayout().

1028 {
1029  d_func()->ownedByLayout = ownership;
1030 }

◆ setParentLayoutItem()

void QGraphicsLayoutItem::setParentLayoutItem ( QGraphicsLayoutItem parent)

◆ setPreferredHeight()

void QGraphicsLayoutItem::setPreferredHeight ( qreal  height)

Sets the preferred height to height.

See also
preferredWidth(), setPreferredSize(), preferredSize()

Definition at line 676 of file qgraphicslayoutitem.cpp.

677 {
679 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSizeComponent(Qt::SizeHint which, SizeComponent component, qreal value)
Sets the width of the user size hint which to width.

◆ setPreferredSize() [1/2]

void QGraphicsLayoutItem::setPreferredSize ( const QSizeF size)

Sets the preferred size to size.

This property overrides sizeHint() for Qt::PreferredSize and provides the default value for effectiveSizeHint(). In order to unset the preferred size, use an invalid size.

See also
preferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, sizeHint()

Definition at line 643 of file qgraphicslayoutitem.cpp.

644 {
646 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSize(Qt::SizeHint which, const QSizeF &size)
Sets the user size hint which to size.

◆ setPreferredSize() [2/2]

void QGraphicsLayoutItem::setPreferredSize ( qreal  w,
qreal  h 
)
inline

This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)).

See also
preferredSize(), setMaximumSize(), setMinimumSize(), sizeHint()

Definition at line 129 of file qgraphicslayoutitem.h.

130 { setPreferredSize(QSizeF(aw, ah)); }
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setPreferredSize(const QSizeF &size)
Sets the preferred size to size.

◆ setPreferredWidth()

void QGraphicsLayoutItem::setPreferredWidth ( qreal  width)

Sets the preferred width to width.

See also
preferredHeight(), setPreferredSize(), preferredSize()

Definition at line 686 of file qgraphicslayoutitem.cpp.

687 {
689 }
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
void setSizeComponent(Qt::SizeHint which, SizeComponent component, qreal value)
Sets the width of the user size hint which to width.

◆ setSizePolicy() [1/2]

void QGraphicsLayoutItem::setSizePolicy ( const QSizePolicy policy)

Sets the size policy to policy.

The size policy describes how the item should grow horizontally and vertically when arranged in a layout.

QGraphicsLayoutItem's default size policy is (QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::DefaultType), but it is common for subclasses to change the default. For example, QGraphicsWidget defaults to (QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType).

See also
sizePolicy(), QWidget::sizePolicy()

Definition at line 539 of file qgraphicslayoutitem.cpp.

Referenced by setSizePolicy().

540 {
542  if (d->sizePolicy == policy)
543  return;
544  d->sizePolicy = policy;
545  updateGeometry();
546 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void updateGeometry()
This virtual function discards any cached size hint information.
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...

◆ setSizePolicy() [2/2]

void QGraphicsLayoutItem::setSizePolicy ( QSizePolicy::Policy  hPolicy,
QSizePolicy::Policy  vPolicy,
QSizePolicy::ControlType  controlType = QSizePolicy::DefaultType 
)

This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
sizePolicy(), QWidget::sizePolicy()

Definition at line 559 of file qgraphicslayoutitem.cpp.

562 {
563  setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType));
564 }
void setSizePolicy(const QSizePolicy &policy)
Sets the size policy to policy.

◆ sizeHint()

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

This pure virtual function returns the size hint for which of the QGraphicsLayoutItem, using the width or height of constraint to constrain the output.

Reimplement this function in a subclass of QGraphicsLayoutItem to provide the necessary size hints for your items.

See also
effectiveSizeHint()

Implemented in QGraphicsWidget, QGraphicsProxyWidget, QGraphicsGridLayout, QGraphicsAnchorLayout, QGraphicsLinearLayout, and QDeclarativeLayoutItem.

Referenced by QGraphicsLinearLayout::addStretch().

◆ sizePolicy()

QSizePolicy QGraphicsLayoutItem::sizePolicy ( ) const

Returns the current size policy.

See also
setSizePolicy(), QWidget::sizePolicy()

Definition at line 571 of file qgraphicslayoutitem.cpp.

Referenced by QGridLayoutItem::controlTypes(), and QGridLayoutItem::sizePolicy().

572 {
573  Q_D(const QGraphicsLayoutItem);
574  return d->sizePolicy;
575 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...

◆ updateGeometry()

void QGraphicsLayoutItem::updateGeometry ( )
virtual

This virtual function discards any cached size hint information.

You should always call this function if you change the return value of the sizeHint() function. Subclasses must always call the base implementation when reimplementing this function.

See also
effectiveSizeHint()

Reimplemented in QGraphicsWidget, and QGraphicsLayout.

Definition at line 944 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayout::activate(), setSizePolicy(), QGraphicsLayout::updateGeometry(), and QGraphicsWidget::updateGeometry().

945 {
947  d->sizeHintCacheDirty = true;
948  d->sizeHintWithConstraintCacheDirty = true;
949 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...

Friends and Related Functions

◆ QGraphicsLayout

friend class QGraphicsLayout
friend

Definition at line 122 of file qgraphicslayoutitem.h.

Properties

◆ d_ptr

QScopedPointer<QGraphicsLayoutItemPrivate> QGraphicsLayoutItem::d_ptr
protected

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