Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QGraphicsLinearLayout Class Reference

The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View. More...

#include <qgraphicslinearlayout.h>

+ Inheritance diagram for QGraphicsLinearLayout:
+ Collaboration diagram for QGraphicsLinearLayout:

Public Member Functions

 QGraphicsLinearLayout (QGraphicsLayoutItem *parent=nullptr)
 Constructs a QGraphicsLinearLayout instance using Qt::Horizontal orientation.
 
 QGraphicsLinearLayout (Qt::Orientation orientation, QGraphicsLayoutItem *parent=nullptr)
 Constructs a QGraphicsLinearLayout instance.
 
virtual ~QGraphicsLinearLayout ()
 Destroys the QGraphicsLinearLayout object.
 
void setOrientation (Qt::Orientation orientation)
 Change the layout orientation to orientation.
 
Qt::Orientation orientation () const
 Returns the layout orientation.
 
void addItem (QGraphicsLayoutItem *item)
 This convenience function is equivalent to calling insertItem(-1, item).
 
void addStretch (int stretch=1)
 This convenience function is equivalent to calling insertStretch(-1, stretch).
 
void insertItem (int index, QGraphicsLayoutItem *item)
 Inserts item into the layout at index, or before any item that is currently at index.
 
void insertStretch (int index, int stretch=1)
 Inserts a stretch of stretch at index, or before any item that is currently at index.
 
void removeItem (QGraphicsLayoutItem *item)
 Removes item from the layout without destroying it.
 
void removeAt (int index) override
 Removes the item at index without destroying it.
 
void setSpacing (qreal spacing)
 Sets the layout's spacing to spacing.
 
qreal spacing () const
 Returns the layout's spacing.
 
void setItemSpacing (int index, qreal spacing)
 Sets the spacing after item at index to spacing.
 
qreal itemSpacing (int index) const
 Returns the spacing after item at index.
 
void setStretchFactor (QGraphicsLayoutItem *item, int stretch)
 Sets the stretch factor for item to stretch.
 
int stretchFactor (QGraphicsLayoutItem *item) const
 Returns the stretch factor for item.
 
void setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment)
 Sets the alignment of item to alignment.
 
Qt::Alignment alignment (QGraphicsLayoutItem *item) const
 Returns the alignment for item.
 
void setGeometry (const QRectF &rect) override
 \reimp
 
int count () const override
 \reimp
 
QGraphicsLayoutItemitemAt (int index) const override
 \reimp When iterating from 0 and up, it will return the items in the visual arranged order.
 
void invalidate () override
 \reimp
 
QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const override
 \reimp
 
void dump (int indent=0) const
 
- Public Member Functions inherited from QGraphicsLayout
 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 updateGeometry () override
 \reimp
 
virtual void widgetEvent (QEvent *e)
 This virtual event handler receives all events for the managed widget.
 
- Public Member Functions inherited from QGraphicsLayoutItem
 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.
 
QRectF geometry () const
 Returns the item's geometry (e.g., position and size) as a QRectF.
 
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 bool isEmpty () const
 
QGraphicsLayoutItemparentLayoutItem () 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.
 
QGraphicsItemgraphicsItem () const
 Returns the QGraphicsItem that this layout item represents.
 
bool ownedByLayout () const
 

Additional Inherited Members

- Static Public Member Functions inherited from QGraphicsLayout
static void setInstantInvalidatePropagation (bool enable)
 
static bool instantInvalidatePropagation ()
 
- Protected Member Functions inherited from QGraphicsLayout
 QGraphicsLayout (QGraphicsLayoutPrivate &, QGraphicsLayoutItem *)
 
void addChildLayoutItem (QGraphicsLayoutItem *layoutItem)
 
- Protected Member Functions inherited from QGraphicsLayoutItem
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)
 
- Protected Attributes inherited from QGraphicsLayoutItem
QScopedPointer< QGraphicsLayoutItemPrivated_ptr
 

Detailed Description

The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View.

Since
4.4

\inmodule QtWidgets

The default orientation for a linear layout is Qt::Horizontal. You can choose a vertical orientation either by calling setOrientation(), or by passing Qt::Vertical to QGraphicsLinearLayout's constructor.

The most common way to use QGraphicsLinearLayout is to construct an object on the heap, passing a parent widget to the constructor, then add widgets and layouts by calling addItem().

The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void addItem(QGraphicsLayoutItem *item)
This convenience function is equivalent to calling insertItem(-1, item).
QGraphicsWidget * pushButton
QGraphicsLinearLayout * layout

Alternatively, if you do not pass a parent widget to the layout's constructor, you will need to call QGraphicsWidget::setLayout() to set this layout as the top-level layout for that widget, the widget will take ownership of the layout.

You can add widgets, layouts, stretches (addStretch(), insertStretch() or setStretchFactor()), and spacings (setItemSpacing()) to a linear layout. The layout takes ownership of the items. In some cases when the layout item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation of QGraphicsLayoutItem::setOwnedByLayout() how to handle this. You can access each item in the layout by calling count() and itemAt(). Calling removeAt() or removeItem() will remove an item from the layout, without destroying it.

Definition at line 17 of file qgraphicslinearlayout.h.

Constructor & Destructor Documentation

◆ QGraphicsLinearLayout() [1/2]

QGraphicsLinearLayout::QGraphicsLinearLayout ( QGraphicsLayoutItem * parent = nullptr)

Constructs a QGraphicsLinearLayout instance using Qt::Horizontal orientation.

parent is passed to QGraphicsLayout's constructor.

Definition at line 165 of file qgraphicslinearlayout.cpp.

◆ QGraphicsLinearLayout() [2/2]

QGraphicsLinearLayout::QGraphicsLinearLayout ( Qt::Orientation orientation,
QGraphicsLayoutItem * parent = nullptr )

Constructs a QGraphicsLinearLayout instance.

You can pass the orientation for the layout, either horizontal or vertical, and parent is passed to QGraphicsLayout's constructor.

Definition at line 156 of file qgraphicslinearlayout.cpp.

◆ ~QGraphicsLinearLayout()

QGraphicsLinearLayout::~QGraphicsLinearLayout ( )
virtual

Destroys the QGraphicsLinearLayout object.

Definition at line 173 of file qgraphicslinearlayout.cpp.

References count(), i, item, itemAt(), and removeAt().

+ Here is the call graph for this function:

Member Function Documentation

◆ addItem()

void QGraphicsLinearLayout::addItem ( QGraphicsLayoutItem * item)
inline

This convenience function is equivalent to calling insertItem(-1, item).

Definition at line 27 of file qgraphicslinearlayout.h.

References item.

◆ addStretch()

void QGraphicsLinearLayout::addStretch ( int stretch = 1)
inline

This convenience function is equivalent to calling insertStretch(-1, stretch).

Definition at line 28 of file qgraphicslinearlayout.h.

◆ alignment()

Qt::Alignment QGraphicsLinearLayout::alignment ( QGraphicsLayoutItem * item) const

Returns the alignment for item.

The default alignment is Qt::AlignTop | Qt::AlignLeft.

The alignment decides how the item is positioned within its assigned space in the case where there's more space available in the layout than the widgets can occupy.

See also
setAlignment()

Definition at line 423 of file qgraphicslinearlayout.cpp.

References d, and item.

◆ count()

int QGraphicsLinearLayout::count ( ) const
overridevirtual

\reimp

Implements QGraphicsLayout.

Definition at line 439 of file qgraphicslinearlayout.cpp.

References d.

Referenced by ~QGraphicsLinearLayout().

+ Here is the caller graph for this function:

◆ dump()

void QGraphicsLinearLayout::dump ( int indent = 0) const

Definition at line 520 of file qgraphicslinearlayout.cpp.

References d, Qt::Horizontal, Q_UNUSED, and qDebug.

Referenced by setGeometry().

+ Here is the caller graph for this function:

◆ insertItem()

void QGraphicsLinearLayout::insertItem ( int index,
QGraphicsLayoutItem * item )

Inserts item into the layout at index, or before any item that is currently at index.

See also
addItem(), itemAt(), insertStretch(), setItemSpacing()

Definition at line 235 of file qgraphicslinearlayout.cpp.

References d, invalidate(), item, Q_ASSERT, and qWarning.

+ Here is the call graph for this function:

◆ insertStretch()

void QGraphicsLinearLayout::insertStretch ( int index,
int stretch = 1 )

Inserts a stretch of stretch at index, or before any item that is currently at index.

See also
addStretch(), setStretchFactor(), setItemSpacing(), insertItem()

Definition at line 262 of file qgraphicslinearlayout.cpp.

References d, and invalidate().

+ Here is the call graph for this function:

◆ invalidate()

void QGraphicsLinearLayout::invalidate ( )
overridevirtual

\reimp

Reimplemented from QGraphicsLayout.

Definition at line 508 of file qgraphicslinearlayout.cpp.

References d, and QGraphicsLayout::invalidate().

Referenced by insertItem(), insertStretch(), removeAt(), removeItem(), setAlignment(), setItemSpacing(), setOrientation(), setSpacing(), and setStretchFactor().

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

◆ itemAt()

QGraphicsLayoutItem * QGraphicsLinearLayout::itemAt ( int index) const
overridevirtual

\reimp When iterating from 0 and up, it will return the items in the visual arranged order.

Implements QGraphicsLayout.

Definition at line 449 of file qgraphicslinearlayout.cpp.

References d, item, and qWarning.

Referenced by ~QGraphicsLinearLayout().

+ Here is the caller graph for this function:

◆ itemSpacing()

qreal QGraphicsLinearLayout::itemSpacing ( int index) const

Returns the spacing after item at index.

Definition at line 352 of file qgraphicslinearlayout.cpp.

References d.

◆ orientation()

Qt::Orientation QGraphicsLinearLayout::orientation ( ) const

Returns the layout orientation.

See also
setOrientation()

Definition at line 209 of file qgraphicslinearlayout.cpp.

References d.

Referenced by setOrientation().

+ Here is the caller graph for this function:

◆ removeAt()

void QGraphicsLinearLayout::removeAt ( int index)
overridevirtual

Removes the item at index without destroying it.

Ownership of the item is transferred to the caller.

See also
removeItem(), insertItem()

Implements QGraphicsLayout.

Definition at line 294 of file qgraphicslinearlayout.cpp.

References d, invalidate(), layoutItem(), and qWarning.

Referenced by ~QGraphicsLinearLayout().

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

◆ removeItem()

void QGraphicsLinearLayout::removeItem ( QGraphicsLayoutItem * item)

Removes item from the layout without destroying it.

Ownership of item is transferred to the caller.

See also
removeAt(), insertItem()

Definition at line 277 of file qgraphicslinearlayout.cpp.

References d, invalidate(), and item.

+ Here is the call graph for this function:

◆ setAlignment()

void QGraphicsLinearLayout::setAlignment ( QGraphicsLayoutItem * item,
Qt::Alignment alignment )

Sets the alignment of item to alignment.

If item's alignment changes, the layout is automatically invalidated.

See also
alignment(), invalidate()

Definition at line 404 of file qgraphicslinearlayout.cpp.

References alignment, d, invalidate(), and item.

+ Here is the call graph for this function:

◆ setGeometry()

void QGraphicsLinearLayout::setGeometry ( const QRectF & rect)
overridevirtual

\reimp

Reimplemented from QGraphicsLayoutItem.

Definition at line 465 of file qgraphicslinearlayout.cpp.

References d, dump(), QGraphicsLayoutItem::geometry(), QGraphicsLayout::getContentsMargins(), qDebug, qSwap(), rect, Qt::RightToLeft, and QGraphicsLayoutItem::setGeometry().

+ Here is the call graph for this function:

◆ setItemSpacing()

void QGraphicsLinearLayout::setItemSpacing ( int index,
qreal spacing )

Sets the spacing after item at index to spacing.

Definition at line 343 of file qgraphicslinearlayout.cpp.

References d, invalidate(), and spacing().

+ Here is the call graph for this function:

◆ setOrientation()

void QGraphicsLinearLayout::setOrientation ( Qt::Orientation orientation)

Change the layout orientation to orientation.

Changing the layout orientation will automatically invalidate the layout.

See also
orientation()

Definition at line 195 of file qgraphicslinearlayout.cpp.

References d, invalidate(), and orientation().

+ Here is the call graph for this function:

◆ setSpacing()

void QGraphicsLinearLayout::setSpacing ( qreal spacing)

Sets the layout's spacing to spacing.

Spacing refers to the vertical and horizontal distances between items.

See also
setItemSpacing(), setStretchFactor(), QGraphicsGridLayout::setSpacing()

Definition at line 317 of file qgraphicslinearlayout.cpp.

References d, Qt::Horizontal, invalidate(), qWarning, spacing(), and Qt::Vertical.

+ Here is the call graph for this function:

◆ setStretchFactor()

void QGraphicsLinearLayout::setStretchFactor ( QGraphicsLayoutItem * item,
int stretch )

Sets the stretch factor for item to stretch.

If an item's stretch factor changes, this function will invalidate the layout.

Setting stretch to 0 removes the stretch factor from the item, and is effectively equivalent to setting stretch to 1.

See also
stretchFactor()

Definition at line 367 of file qgraphicslinearlayout.cpp.

References d, invalidate(), item, qWarning, and stretchFactor().

+ Here is the call graph for this function:

◆ sizeHint()

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

\reimp

Implements QGraphicsLayoutItem.

Definition at line 496 of file qgraphicslinearlayout.cpp.

References d, and QGraphicsLayout::getContentsMargins().

+ Here is the call graph for this function:

◆ spacing()

qreal QGraphicsLinearLayout::spacing ( ) const

Returns the layout's spacing.

Spacing refers to the vertical and horizontal distances between items.

See also
setSpacing()

Definition at line 334 of file qgraphicslinearlayout.cpp.

References d.

Referenced by setItemSpacing(), and setSpacing().

+ Here is the caller graph for this function:

◆ stretchFactor()

int QGraphicsLinearLayout::stretchFactor ( QGraphicsLayoutItem * item) const

Returns the stretch factor for item.

The default stretch factor is 0, meaning that the item has no assigned stretch factor.

See also
setStretchFactor()

Definition at line 387 of file qgraphicslinearlayout.cpp.

References d, item, and qWarning.

Referenced by setStretchFactor().

+ Here is the caller graph for this function:

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