QtBase  v6.3.1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
QGraphicsLayout Class Referenceabstract

The QGraphicsLayout class provides the base class for all layouts in Graphics View. More...

#include <qgraphicslayout.h>

Inheritance diagram for QGraphicsLayout:
Inheritance graph
[legend]
Collaboration diagram for QGraphicsLayout:
Collaboration graph
[legend]

Public Member Functions

 QGraphicsLayout (QGraphicsLayoutItem *parent=nullptr)
 
 ~QGraphicsLayout ()
 
void setContentsMargins (qreal left, qreal top, qreal right, qreal bottom)
 
void getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const override
 
void activate ()
 
bool isActivated () const
 
virtual void invalidate ()
 
virtual void updateGeometry () override
 
virtual void widgetEvent (QEvent *e)
 
virtual int count () const =0
 
virtual QGraphicsLayoutItemitemAt (int i) const =0
 
virtual void removeAt (int index)=0
 
- Public Member Functions inherited from QGraphicsLayoutItem
 QGraphicsLayoutItem (QGraphicsLayoutItem *parent=nullptr, bool isLayout=false)
 
virtual ~QGraphicsLayoutItem ()
 
void setSizePolicy (const QSizePolicy &policy)
 
void setSizePolicy (QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType=QSizePolicy::DefaultType)
 
QSizePolicy sizePolicy () const
 
void setMinimumSize (const QSizeF &size)
 
void setMinimumSize (qreal w, qreal h)
 
QSizeF minimumSize () const
 
void setMinimumWidth (qreal width)
 
qreal minimumWidth () const
 
void setMinimumHeight (qreal height)
 
qreal minimumHeight () const
 
void setPreferredSize (const QSizeF &size)
 
void setPreferredSize (qreal w, qreal h)
 
QSizeF preferredSize () const
 
void setPreferredWidth (qreal width)
 
qreal preferredWidth () const
 
void setPreferredHeight (qreal height)
 
qreal preferredHeight () const
 
void setMaximumSize (const QSizeF &size)
 
void setMaximumSize (qreal w, qreal h)
 
QSizeF maximumSize () const
 
void setMaximumWidth (qreal width)
 
qreal maximumWidth () const
 
void setMaximumHeight (qreal height)
 
qreal maximumHeight () const
 
virtual void setGeometry (const QRectF &rect)
 
QRectF geometry () const
 
QRectF contentsRect () const
 
QSizeF effectiveSizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
 
virtual bool isEmpty () const
 
QGraphicsLayoutItemparentLayoutItem () const
 
void setParentLayoutItem (QGraphicsLayoutItem *parent)
 
bool isLayout () const
 
QGraphicsItemgraphicsItem () const
 
bool ownedByLayout () const
 

Static Public Member Functions

static void setInstantInvalidatePropagation (bool enable)
 
static bool instantInvalidatePropagation ()
 

Protected Member Functions

 QGraphicsLayout (QGraphicsLayoutPrivate &, QGraphicsLayoutItem *)
 
void addChildLayoutItem (QGraphicsLayoutItem *layoutItem)
 
- Protected Member Functions inherited from QGraphicsLayoutItem
void setGraphicsItem (QGraphicsItem *item)
 
void setOwnedByLayout (bool ownedByLayout)
 
 QGraphicsLayoutItem (QGraphicsLayoutItemPrivate &dd)
 
virtual QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const =0
 

Friends

class QGraphicsWidget
 

Additional Inherited Members

- Protected Attributes inherited from QGraphicsLayoutItem
QScopedPointer< QGraphicsLayoutItemPrivated_ptr
 

Detailed Description

The QGraphicsLayout class provides the base class for all layouts in Graphics View.

Since
4.4

\inmodule QtWidgets

QGraphicsLayout is an abstract class that defines a virtual API for arranging QGraphicsWidget children and other QGraphicsLayoutItem objects for a QGraphicsWidget. QGraphicsWidget assigns responsibility to a QGraphicsLayout through QGraphicsWidget::setLayout(). As the widget is resized, the layout will automatically arrange the widget's children. QGraphicsLayout inherits QGraphicsLayoutItem, so, it can be managed by any layout, including its own subclasses.

Definition at line 54 of file qgraphicslayout.h.

Constructor & Destructor Documentation

◆ QGraphicsLayout() [1/2]

QGraphicsLayout::QGraphicsLayout ( QGraphicsLayoutItem parent = nullptr)

Constructs a QGraphicsLayout object.

parent is passed to QGraphicsLayoutItem's constructor and the QGraphicsLayoutItem's isLayout argument is set to true.

If parent is a QGraphicsWidget the layout will be installed on that widget. (Note that installing a layout will delete the old one installed.)

Definition at line 158 of file qgraphicslayout.cpp.

Here is the call graph for this function:

◆ ~QGraphicsLayout()

QGraphicsLayout::~QGraphicsLayout ( )

Destroys the QGraphicsLayout object.

Definition at line 200 of file qgraphicslayout.cpp.

◆ QGraphicsLayout() [2/2]

QGraphicsLayout::QGraphicsLayout ( QGraphicsLayoutPrivate dd,
QGraphicsLayoutItem parent 
)
protected

Definition at line 179 of file qgraphicslayout.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ activate()

void QGraphicsLayout::activate ( )

Activates the layout, causing all items in the layout to be immediately rearranged. This function is based on calling count() and itemAt(), and then calling setGeometry() on all items sequentially. When activated, the layout will adjust its geometry to its parent's contentsRect(). The parent will then invalidate any layout of its own.

If called in sequence or recursively, e.g., by one of the arranged items in response to being resized, this function will do nothing.

Note that the layout is free to use geometry caching to optimize this process. To forcefully invalidate any such cache, you can call invalidate() before calling activate().

See also
invalidate()

Definition at line 257 of file qgraphicslayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addChildLayoutItem()

void QGraphicsLayout::addChildLayoutItem ( QGraphicsLayoutItem layoutItem)
protected
Since
4.6

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.

If layoutItem is already in a different layout, it will be removed from that layout.

If custom layouts want special behaviour they can ignore to use this function, and implement their own behaviour.

See also
graphicsItem()

Definition at line 472 of file qgraphicslayout.cpp.

◆ count()

int QGraphicsLayout::count ( ) const
pure virtual

This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return the number of items in the layout.

The subclass is free to decide how to store the items.

See also
itemAt(), removeAt()

Implemented in CustomLayout, Layout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsAnchorLayout, FlowLayout, and FlowLayout.

Here is the caller graph for this function:

◆ getContentsMargins()

void QGraphicsLayout::getContentsMargins ( qreal left,
qreal top,
qreal right,
qreal bottom 
) const
overridevirtual

\reimp

Reimplemented from QGraphicsLayoutItem.

Definition at line 232 of file qgraphicslayout.cpp.

Here is the caller graph for this function:

◆ instantInvalidatePropagation()

bool QGraphicsLayout::instantInvalidatePropagation ( )
static

Definition at line 517 of file qgraphicslayout.cpp.

Here is the caller graph for this function:

◆ invalidate()

void QGraphicsLayout::invalidate ( )
virtual

Clears any cached geometry and size hint information in the layout, and posts a \l{QEvent::LayoutRequest}{LayoutRequest} event to the managed parent QGraphicsLayoutItem.

See also
activate(), setGeometry()

Reimplemented in TestLayout, TestLayout, QGraphicsLinearLayout, QGraphicsGridLayout, and QGraphicsAnchorLayout.

Definition at line 311 of file qgraphicslayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isActivated()

bool QGraphicsLayout::isActivated ( ) const

Returns true if the layout is currently being activated; otherwise, returns false. If the layout is being activated, this means that it is currently in the process of rearranging its items (i.e., the activate() function has been called, and has not yet returned).

See also
activate(), invalidate()

Definition at line 298 of file qgraphicslayout.cpp.

Here is the caller graph for this function:

◆ itemAt()

QGraphicsLayoutItem * QGraphicsLayout::itemAt ( int  i) const
pure virtual

This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return a pointer to the item at index i. The reimplementation can assume that i is valid (i.e., it respects the value of count()). Together with count(), it is provided as a means of iterating over all items in a layout.

The subclass is free to decide how to store the items, and the visual arrangement does not have to be reflected through this function.

See also
count(), removeAt()

Implemented in CustomLayout, Layout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsAnchorLayout, FlowLayout, and FlowLayout.

Here is the caller graph for this function:

◆ removeAt()

void QGraphicsLayout::removeAt ( int  index)
pure virtual

This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to remove the item at index. The reimplementation can assume that index is valid (i.e., it respects the value of count()).

The implementation must ensure that the parentLayoutItem() of the removed item does not point to this layout, since the item is considered to be removed from the layout hierarchy.

If the layout is to be reused between applications, we recommend that the layout deletes the item, but the graphics view framework does not depend on this.

The subclass is free to decide how to store the items.

See also
itemAt(), count()

Implemented in CustomLayout, Layout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsAnchorLayout, and FlowLayout.

Here is the caller graph for this function:

◆ setContentsMargins()

void QGraphicsLayout::setContentsMargins ( qreal  left,
qreal  top,
qreal  right,
qreal  bottom 
)

Sets the contents margins to left, top, right and bottom. The default contents margins for toplevel layouts are style dependent (by querying the pixelMetric for QStyle::PM_LayoutLeftMargin, QStyle::PM_LayoutTopMargin, QStyle::PM_LayoutRightMargin and QStyle::PM_LayoutBottomMargin).

For sublayouts the default margins are 0.

Changing the contents margins automatically invalidates the layout.

See also
invalidate()

Definition at line 217 of file qgraphicslayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInstantInvalidatePropagation()

void QGraphicsLayout::setInstantInvalidatePropagation ( bool  enable)
static

Definition at line 505 of file qgraphicslayout.cpp.

Here is the caller graph for this function:

◆ updateGeometry()

void QGraphicsLayout::updateGeometry ( )
overridevirtual

\reimp

Reimplemented from QGraphicsLayoutItem.

Definition at line 350 of file qgraphicslayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ widgetEvent()

void QGraphicsLayout::widgetEvent ( QEvent e)
virtual

This virtual event handler receives all events for the managed widget. QGraphicsLayout uses this event handler to listen for layout related events such as geometry changes, layout changes or layout direction changes.

e is a pointer to the event.

You can reimplement this event handler to track similar events for your own custom layout.

See also
QGraphicsWidget::event(), QGraphicsItem::sceneEvent()

Reimplemented in SubQGraphicsLinearLayout.

Definition at line 390 of file qgraphicslayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ QGraphicsWidget

friend class QGraphicsWidget
friend

Definition at line 83 of file qgraphicslayout.h.


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