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>.
|
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View. More...
#include <qgraphicslinearlayout.h>
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 | |
QGraphicsLayoutItem * | itemAt (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 |
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 |
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< QGraphicsLayoutItemPrivate > | d_ptr |
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View.
\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().
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.
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::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.
|
virtual |
Destroys the QGraphicsLinearLayout object.
Definition at line 173 of file qgraphicslinearlayout.cpp.
References count(), i, item, itemAt(), and removeAt().
|
inline |
This convenience function is equivalent to calling insertItem(-1, item).
Definition at line 27 of file qgraphicslinearlayout.h.
References item.
|
inline |
This convenience function is equivalent to calling insertStretch(-1, stretch).
Definition at line 28 of file qgraphicslinearlayout.h.
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.
Definition at line 423 of file qgraphicslinearlayout.cpp.
|
overridevirtual |
\reimp
Implements QGraphicsLayout.
Definition at line 439 of file qgraphicslinearlayout.cpp.
References d.
Referenced by ~QGraphicsLinearLayout().
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().
void QGraphicsLinearLayout::insertItem | ( | int | index, |
QGraphicsLayoutItem * | item ) |
Inserts item into the layout at index, or before any item that is currently at index.
Definition at line 235 of file qgraphicslinearlayout.cpp.
References d, invalidate(), item, Q_ASSERT, and qWarning.
void QGraphicsLinearLayout::insertStretch | ( | int | index, |
int | stretch = 1 ) |
Inserts a stretch of stretch at index, or before any item that is currently at index.
Definition at line 262 of file qgraphicslinearlayout.cpp.
References d, and 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().
|
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().
qreal QGraphicsLinearLayout::itemSpacing | ( | int | index | ) | const |
Returns the spacing after item at index.
Definition at line 352 of file qgraphicslinearlayout.cpp.
References d.
Qt::Orientation QGraphicsLinearLayout::orientation | ( | ) | const |
Returns the layout orientation.
Definition at line 209 of file qgraphicslinearlayout.cpp.
References d.
Referenced by setOrientation().
|
overridevirtual |
Removes the item at index without destroying it.
Ownership of the item is transferred to the caller.
Implements QGraphicsLayout.
Definition at line 294 of file qgraphicslinearlayout.cpp.
References d, invalidate(), layoutItem(), and qWarning.
Referenced by ~QGraphicsLinearLayout().
void QGraphicsLinearLayout::removeItem | ( | QGraphicsLayoutItem * | item | ) |
Removes item from the layout without destroying it.
Ownership of item is transferred to the caller.
Definition at line 277 of file qgraphicslinearlayout.cpp.
References d, invalidate(), and item.
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.
Definition at line 404 of file qgraphicslinearlayout.cpp.
References alignment, d, invalidate(), and item.
\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().
Sets the spacing after item at index to spacing.
Definition at line 343 of file qgraphicslinearlayout.cpp.
References d, invalidate(), and spacing().
void QGraphicsLinearLayout::setOrientation | ( | Qt::Orientation | orientation | ) |
Change the layout orientation to orientation.
Changing the layout orientation will automatically invalidate the layout.
Definition at line 195 of file qgraphicslinearlayout.cpp.
References d, invalidate(), and orientation().
Sets the layout's spacing to spacing.
Spacing refers to the vertical and horizontal distances between items.
Definition at line 317 of file qgraphicslinearlayout.cpp.
References d, Qt::Horizontal, invalidate(), qWarning, spacing(), and Qt::Vertical.
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.
Definition at line 367 of file qgraphicslinearlayout.cpp.
References d, invalidate(), item, qWarning, and stretchFactor().
|
overridevirtual |
\reimp
Implements QGraphicsLayoutItem.
Definition at line 496 of file qgraphicslinearlayout.cpp.
References d, and QGraphicsLayout::getContentsMargins().
qreal QGraphicsLinearLayout::spacing | ( | ) | const |
Returns the layout's spacing.
Spacing refers to the vertical and horizontal distances between items.
Definition at line 334 of file qgraphicslinearlayout.cpp.
References d.
Referenced by setItemSpacing(), and setSpacing().
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.
Definition at line 387 of file qgraphicslinearlayout.cpp.
References d, item, and qWarning.
Referenced by setStretchFactor().