![]() |
Qt 6.x
The Qt SDK
|
The QGraphicsLayout class provides the base class for all layouts in Graphics View. More...
#include <qgraphicslayout.h>
Public Member Functions | |
QGraphicsLayout (QGraphicsLayoutItem *parent=nullptr) | |
Constructs a QGraphicsLayout object. | |
~QGraphicsLayout () | |
Destroys the QGraphicsLayout object. | |
void | setContentsMargins (qreal left, qreal top, qreal right, qreal bottom) |
Sets the contents margins to left, top, right and bottom. | |
void | getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const override |
\reimp | |
void | activate () |
Activates the layout, causing all items in the layout to be immediately rearranged. | |
bool | isActivated () const |
Returns true if the layout is currently being activated; otherwise, returns false . | |
virtual void | invalidate () |
Clears any cached geometry and size hint information in the layout, and posts a \l{QEvent::LayoutRequest}{LayoutRequest} event to the managed parent QGraphicsLayoutItem. | |
virtual void | updateGeometry () override |
\reimp | |
virtual void | widgetEvent (QEvent *e) |
This virtual event handler receives all events for the managed widget. | |
virtual int | count () const =0 |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return the number of items in the layout. | |
virtual QGraphicsLayoutItem * | itemAt (int i) const =0 |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return a pointer to the item at index i. | |
virtual void | removeAt (int index)=0 |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to remove the item at index. | |
![]() | |
QGraphicsLayoutItem (QGraphicsLayoutItem *parent=nullptr, bool isLayout=false) | |
Constructs the QGraphicsLayoutItem object. | |
virtual | ~QGraphicsLayoutItem () |
Destroys the QGraphicsLayoutItem object. | |
void | setSizePolicy (const QSizePolicy &policy) |
Sets the size policy to policy. | |
void | setSizePolicy (QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType=QSizePolicy::DefaultType) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)). | |
QSizePolicy | sizePolicy () const |
Returns the current size policy. | |
void | setMinimumSize (const QSizeF &size) |
Sets the minimum size to size. | |
void | setMinimumSize (qreal w, qreal h) |
This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)). | |
QSizeF | minimumSize () const |
Returns the minimum size. | |
void | setMinimumWidth (qreal width) |
Sets the minimum width to width. | |
qreal | minimumWidth () const |
Returns the minimum width. | |
void | setMinimumHeight (qreal height) |
Sets the minimum height to height. | |
qreal | minimumHeight () const |
Returns the minimum height. | |
void | setPreferredSize (const QSizeF &size) |
Sets the preferred size to size. | |
void | setPreferredSize (qreal w, qreal h) |
This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)). | |
QSizeF | preferredSize () const |
Returns the preferred size. | |
void | setPreferredWidth (qreal width) |
Sets the preferred width to width. | |
qreal | preferredWidth () const |
Returns the preferred width. | |
void | setPreferredHeight (qreal height) |
Sets the preferred height to height. | |
qreal | preferredHeight () const |
Returns the preferred height. | |
void | setMaximumSize (const QSizeF &size) |
Sets the maximum size to size. | |
void | setMaximumSize (qreal w, qreal h) |
This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)). | |
QSizeF | maximumSize () const |
Returns the maximum size. | |
void | setMaximumWidth (qreal width) |
Sets the maximum width to width. | |
qreal | maximumWidth () const |
Returns the maximum width. | |
void | setMaximumHeight (qreal height) |
Sets the maximum height to height. | |
qreal | maximumHeight () const |
Returns the maximum height. | |
virtual void | setGeometry (const QRectF &rect) |
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). | |
QRectF | geometry () const |
Returns the item's geometry (e.g., position and size) as a QRectF. | |
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. | |
QRectF | contentsRect () const |
Returns the contents rect in local coordinates. | |
QSizeF | effectiveSizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const |
Returns the effective size hint for this QGraphicsLayoutItem. | |
virtual void | updateGeometry () |
This virtual function discards any cached size hint information. | |
virtual bool | isEmpty () const |
QGraphicsLayoutItem * | parentLayoutItem () const |
Returns the parent of this QGraphicsLayoutItem, or \nullptr 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). | |
void | setParentLayoutItem (QGraphicsLayoutItem *parent) |
Sets the parent of this QGraphicsLayoutItem to parent. | |
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 . | |
QGraphicsItem * | graphicsItem () const |
Returns the QGraphicsItem that this layout item represents. | |
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) |
![]() | |
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. | |
void | setOwnedByLayout (bool ownedByLayout) |
QGraphicsLayoutItem (QGraphicsLayoutItemPrivate &dd) | |
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. | |
Friends | |
class | QGraphicsWidget |
Additional Inherited Members | |
![]() | |
QScopedPointer< QGraphicsLayoutItemPrivate > | d_ptr |
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
\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 18 of file qgraphicslayout.h.
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 122 of file qgraphicslayout.cpp.
References QSizePolicy::DefaultType, QSizePolicy::Expanding, QGraphicsItem::isWidget(), parent, qWarning, QGraphicsLayoutItem::setOwnedByLayout(), and QGraphicsLayoutItem::setParentLayoutItem().
QGraphicsLayout::~QGraphicsLayout | ( | ) |
Destroys the QGraphicsLayout object.
Definition at line 164 of file qgraphicslayout.cpp.
|
protected |
Definition at line 143 of file qgraphicslayout.cpp.
References QSizePolicy::DefaultType, QSizePolicy::Expanding, QGraphicsItem::isWidget(), parent, qWarning, QGraphicsLayoutItem::setOwnedByLayout(), and QGraphicsLayoutItem::setParentLayoutItem().
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().
Definition at line 221 of file qgraphicslayout.cpp.
References QGraphicsLayoutItem::contentsRect(), d, instantInvalidatePropagation(), QGraphicsLayoutItem::isLayout(), QGraphicsLayoutItem::parentLayoutItem(), Q_ASSERT, QGraphicsWidget::resize(), QGraphicsWidget::setAttribute(), QGraphicsLayoutItem::setGeometry(), QGraphicsWidget::size, QGraphicsWidget::testAttribute(), QGraphicsLayoutItem::updateGeometry(), and Qt::WA_Resized.
Referenced by widgetEvent().
|
protected |
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.
Definition at line 436 of file qgraphicslayout.cpp.
References d, and layoutItem().
|
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.
Implemented in QGraphicsAnchorLayout, QGraphicsGridLayout, and QGraphicsLinearLayout.
Referenced by QGraphicsLayoutItem::~QGraphicsLayoutItem(), QGraphicsLayoutItemPrivate::hasHeightForWidth(), QGraphicsLayoutItemPrivate::hasWidthForHeight(), and removeLayoutItemFromLayout().
|
overridevirtual |
\reimp
Reimplemented from QGraphicsLayoutItem.
Definition at line 196 of file qgraphicslayout.cpp.
References d, QStyle::PM_LayoutBottomMargin, QStyle::PM_LayoutLeftMargin, QStyle::PM_LayoutRightMargin, and QStyle::PM_LayoutTopMargin.
Referenced by QGraphicsGridLayout::setGeometry(), QGraphicsLinearLayout::setGeometry(), QGraphicsAnchorLayout::sizeHint(), QGraphicsGridLayout::sizeHint(), and QGraphicsLinearLayout::sizeHint().
|
static |
returns true
if the complete widget/layout hierarchy is rearranged in one go.
Definition at line 481 of file qgraphicslayout.cpp.
References g_instantInvalidatePropagation.
Referenced by activate(), QGraphicsLayoutPrivate::activateRecursive(), invalidate(), QGraphicsWidget::setGeometry(), updateGeometry(), and QGraphicsWidget::updateGeometry().
|
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.
Reimplemented in QGraphicsAnchorLayout, QGraphicsGridLayout, and QGraphicsLinearLayout.
Definition at line 275 of file qgraphicslayout.cpp.
References instantInvalidatePropagation(), layoutItem(), QEvent::LayoutRequest, QCoreApplication::postEvent(), and updateGeometry().
Referenced by QGraphicsAnchorLayout::invalidate(), QGraphicsGridLayout::invalidate(), QGraphicsLinearLayout::invalidate(), setContentsMargins(), QGraphicsWidget::setLayout(), updateGeometry(), and widgetEvent().
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).
Definition at line 262 of file qgraphicslayout.cpp.
References d.
Referenced by widgetEvent().
|
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.
Implemented in QGraphicsAnchorLayout, QGraphicsGridLayout, and QGraphicsLinearLayout.
Referenced by QGraphicsLayoutItem::~QGraphicsLayoutItem(), QGraphicsLayoutItemPrivate::hasHeightForWidth(), QGraphicsLayoutItemPrivate::hasWidthForHeight(), and removeLayoutItemFromLayout().
|
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.
Implemented in QGraphicsAnchorLayout, QGraphicsGridLayout, and QGraphicsLinearLayout.
Referenced by QGraphicsLayoutItem::~QGraphicsLayoutItem(), and removeLayoutItemFromLayout().
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.
Definition at line 181 of file qgraphicslayout.cpp.
References d, and invalidate().
|
static |
Calling this function with enable set to true will enable a feature that makes propagation of invalidation up to ancestor layout items to be done in one go. It will propagate up the parentLayoutItem() hierarchy until it has reached the root. If the root item is a QGraphicsWidget, it will post a layout request to it. When the layout request is consumed it will traverse down the hierarchy of layouts and widgets and activate all layouts that is invalid (not activated). This is the recommended behaviour.
If not set it will also propagate up the parentLayoutItem() hierarchy, but it will stop at the {first widget} it encounters, and post a layout request to the widget. When the layout request is consumed, this might cause it to continue propagation up to the parentLayoutItem() of the widget. It will continue in this fashion until it has reached a widget with no parentLayoutItem(). This strategy might cause drawing artifacts, since it is not done in one go, and the consumption of layout requests might be interleaved by consumption of paint events, which might cause significant flicker. Note, this is not the recommended behavior, but for compatibility reasons this is the default behaviour.
Definition at line 469 of file qgraphicslayout.cpp.
References g_instantInvalidatePropagation.
|
overridevirtual |
\reimp
Reimplemented from QGraphicsLayoutItem.
Definition at line 314 of file qgraphicslayout.cpp.
References d, instantInvalidatePropagation(), invalidate(), QGraphicsLayoutItem::isLayout(), QGraphicsLayoutItem::parentLayoutItem(), and QGraphicsLayoutItem::updateGeometry().
Referenced by invalidate().
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.
Definition at line 354 of file qgraphicslayout.cpp.
References activate(), QGraphicsLayoutItem::contentsRect(), e, QEvent::GraphicsSceneResize, invalidate(), isActivated(), QEvent::LayoutDirectionChange, QEvent::LayoutRequest, QGraphicsLayoutItem::parentLayoutItem(), and QGraphicsLayoutItem::setGeometry().
|
friend |
Definition at line 47 of file qgraphicslayout.h.