![]() |
Qt 6.x
The Qt SDK
|
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View. More...
#include <qgraphicsgridlayout.h>
Public Member Functions | |
QGraphicsGridLayout (QGraphicsLayoutItem *parent=nullptr) | |
Constructs a QGraphicsGridLayout instance. | |
virtual | ~QGraphicsGridLayout () |
Destroys the QGraphicsGridLayout object. | |
void | addItem (QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment=Qt::Alignment()) |
Adds item to the grid on row and column. | |
void | addItem (QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment=Qt::Alignment()) |
Adds item to the grid on row and column. | |
void | setHorizontalSpacing (qreal spacing) |
Sets the default horizontal spacing for the grid layout to spacing. | |
qreal | horizontalSpacing () const |
Returns the default horizontal spacing for the grid layout. | |
void | setVerticalSpacing (qreal spacing) |
Sets the default vertical spacing for the grid layout to spacing. | |
qreal | verticalSpacing () const |
Returns the default vertical spacing for the grid layout. | |
void | setSpacing (qreal spacing) |
Sets the grid layout's default spacing, both vertical and horizontal, to spacing. | |
void | setRowSpacing (int row, qreal spacing) |
Sets the spacing for row to spacing. | |
qreal | rowSpacing (int row) const |
Returns the row spacing for row. | |
void | setColumnSpacing (int column, qreal spacing) |
Sets the spacing for column to spacing. | |
qreal | columnSpacing (int column) const |
Returns the column spacing for column. | |
void | setRowStretchFactor (int row, int stretch) |
Sets the stretch factor for row to stretch. | |
int | rowStretchFactor (int row) const |
Returns the stretch factor for row. | |
void | setColumnStretchFactor (int column, int stretch) |
Sets the stretch factor for column to stretch. | |
int | columnStretchFactor (int column) const |
Returns the stretch factor for column. | |
void | setRowMinimumHeight (int row, qreal height) |
Sets the minimum height for row, row, to height. | |
qreal | rowMinimumHeight (int row) const |
Returns the minimum height for row, row. | |
void | setRowPreferredHeight (int row, qreal height) |
Sets the preferred height for row, row, to height. | |
qreal | rowPreferredHeight (int row) const |
Returns the preferred height for row, row. | |
void | setRowMaximumHeight (int row, qreal height) |
Sets the maximum height for row, row, to height. | |
qreal | rowMaximumHeight (int row) const |
Returns the maximum height for row, row. | |
void | setRowFixedHeight (int row, qreal height) |
Sets the fixed height for row, row, to height. | |
void | setColumnMinimumWidth (int column, qreal width) |
Sets the minimum width for column to width. | |
qreal | columnMinimumWidth (int column) const |
Returns the minimum width for column. | |
void | setColumnPreferredWidth (int column, qreal width) |
Sets the preferred width for column to width. | |
qreal | columnPreferredWidth (int column) const |
Returns the preferred width for column. | |
void | setColumnMaximumWidth (int column, qreal width) |
Sets the maximum width of column to width. | |
qreal | columnMaximumWidth (int column) const |
Returns the maximum width for column. | |
void | setColumnFixedWidth (int column, qreal width) |
Sets the fixed width of column to width. | |
void | setRowAlignment (int row, Qt::Alignment alignment) |
Sets the alignment of row to alignment. | |
Qt::Alignment | rowAlignment (int row) const |
Returns the alignment of row. | |
void | setColumnAlignment (int column, Qt::Alignment alignment) |
Sets the alignment for column to alignment. | |
Qt::Alignment | columnAlignment (int column) const |
Returns the alignment for column. | |
void | setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment) |
Sets the alignment for item to alignment. | |
Qt::Alignment | alignment (QGraphicsLayoutItem *item) const |
Returns the alignment for item. | |
int | rowCount () const |
Returns the number of rows in the grid layout. | |
int | columnCount () const |
Returns the number of columns in the grid layout. | |
QGraphicsLayoutItem * | itemAt (int row, int column) const |
Returns a pointer to the layout item at (row, column). | |
int | count () const override |
Returns the number of layout items in this grid layout. | |
QGraphicsLayoutItem * | itemAt (int index) const override |
Returns the layout item at index, or \nullptr if there is no layout item at this index. | |
void | removeAt (int index) override |
Removes the layout item at index without destroying it. | |
void | removeItem (QGraphicsLayoutItem *item) |
Removes the layout item item without destroying it. | |
void | invalidate () override |
\reimp | |
void | setGeometry (const QRectF &rect) override |
Sets the bounding geometry of the grid layout to rect. | |
QSizeF | sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const override |
\reimp | |
![]() | |
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 |
Additional Inherited Members | |
![]() | |
static void | setInstantInvalidatePropagation (bool enable) |
static bool | instantInvalidatePropagation () |
![]() | |
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. | |
![]() | |
QScopedPointer< QGraphicsLayoutItemPrivate > | d_ptr |
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.
\inmodule QtWidgets
The most common way to use QGraphicsGridLayout is to construct an object on the heap, passing a parent widget to the constructor, then add widgets and layouts by calling addItem(). QGraphicsGridLayout automatically computes the dimensions of the grid as you add items.
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.
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() will remove an item from the layout, without destroying it.
Definition at line 17 of file qgraphicsgridlayout.h.
QGraphicsGridLayout::QGraphicsGridLayout | ( | QGraphicsLayoutItem * | parent = nullptr | ) |
Constructs a QGraphicsGridLayout instance.
parent is passed to QGraphicsLayout's constructor.
Definition at line 90 of file qgraphicsgridlayout.cpp.
|
virtual |
Destroys the QGraphicsGridLayout object.
Definition at line 98 of file qgraphicsgridlayout.cpp.
References count(), i, item, itemAt(), and removeAt().
void QGraphicsGridLayout::addItem | ( | QGraphicsLayoutItem * | item, |
int | row, | ||
int | column, | ||
int | rowSpan, | ||
int | columnSpan, | ||
Qt::Alignment | alignment = Qt::Alignment() |
||
) |
Adds item to the grid on row and column.
You can specify a rowSpan and columnSpan and an optional alignment.
Definition at line 118 of file qgraphicsgridlayout.cpp.
References alignment, d, invalidate(), item, and qWarning.
Referenced by addItem().
|
inline |
Adds item to the grid on row and column.
You can specify an optional alignment for item.
Definition at line 93 of file qgraphicsgridlayout.h.
References addItem().
Qt::Alignment QGraphicsGridLayout::alignment | ( | QGraphicsLayoutItem * | item | ) | const |
Returns the alignment for item.
Definition at line 469 of file qgraphicsgridlayout.cpp.
Qt::Alignment QGraphicsGridLayout::columnAlignment | ( | int | column | ) | const |
Returns the alignment for column.
Definition at line 450 of file qgraphicsgridlayout.cpp.
References d, and Qt::Horizontal.
int QGraphicsGridLayout::columnCount | ( | ) | const |
Returns the number of columns in the grid layout.
This is always one more than the index of the last column that is occupied by a layout item (empty columns are counted except for those at the end).
Definition at line 491 of file qgraphicsgridlayout.cpp.
References d, and Qt::Horizontal.
Referenced by itemAt().
qreal QGraphicsGridLayout::columnMaximumWidth | ( | int | column | ) | const |
Returns the maximum width for column.
Definition at line 401 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, and Qt::MaximumSize.
qreal QGraphicsGridLayout::columnMinimumWidth | ( | int | column | ) | const |
Returns the minimum width for column.
Definition at line 363 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, and Qt::MinimumSize.
qreal QGraphicsGridLayout::columnPreferredWidth | ( | int | column | ) | const |
Returns the preferred width for column.
Definition at line 382 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, and Qt::PreferredSize.
qreal QGraphicsGridLayout::columnSpacing | ( | int | column | ) | const |
Returns the column spacing for column.
Definition at line 238 of file qgraphicsgridlayout.cpp.
References d, and Qt::Horizontal.
int QGraphicsGridLayout::columnStretchFactor | ( | int | column | ) | const |
Returns the stretch factor for column.
Definition at line 276 of file qgraphicsgridlayout.cpp.
References d, and Qt::Horizontal.
|
overridevirtual |
Returns the number of layout items in this grid layout.
Implements QGraphicsLayout.
Definition at line 515 of file qgraphicsgridlayout.cpp.
References d.
Referenced by ~QGraphicsGridLayout().
qreal QGraphicsGridLayout::horizontalSpacing | ( | ) | const |
Returns the default horizontal spacing for the grid layout.
Definition at line 168 of file qgraphicsgridlayout.cpp.
References d, and Qt::Horizontal.
|
overridevirtual |
\reimp
Reimplemented from QGraphicsLayout.
Definition at line 585 of file qgraphicsgridlayout.cpp.
References d, and QGraphicsLayout::invalidate().
Referenced by addItem(), removeAt(), setAlignment(), setColumnAlignment(), setColumnFixedWidth(), setColumnMaximumWidth(), setColumnMinimumWidth(), setColumnPreferredWidth(), setColumnSpacing(), setColumnStretchFactor(), setHorizontalSpacing(), setRowAlignment(), setRowFixedHeight(), setRowMaximumHeight(), setRowMinimumHeight(), setRowPreferredHeight(), setRowSpacing(), setRowStretchFactor(), setSpacing(), and setVerticalSpacing().
|
overridevirtual |
Returns the layout item at index, or \nullptr if there is no layout item at this index.
Implements QGraphicsLayout.
Definition at line 525 of file qgraphicsgridlayout.cpp.
QGraphicsLayoutItem * QGraphicsGridLayout::itemAt | ( | int | row, |
int | column | ||
) | const |
Returns a pointer to the layout item at (row, column).
Definition at line 500 of file qgraphicsgridlayout.cpp.
References columnCount(), d, qWarning, and rowCount().
Referenced by ~QGraphicsGridLayout().
|
overridevirtual |
Removes the layout item at index without destroying it.
Ownership of the item is transferred to the caller.
Implements QGraphicsLayout.
Definition at line 543 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), layoutItem(), qWarning, and Qt::Vertical.
Referenced by ~QGraphicsGridLayout(), and removeItem().
void QGraphicsGridLayout::removeItem | ( | QGraphicsLayoutItem * | item | ) |
Removes the layout item item without destroying it.
Ownership of the item is transferred to the caller.
Definition at line 576 of file qgraphicsgridlayout.cpp.
References d, item, and removeAt().
Qt::Alignment QGraphicsGridLayout::rowAlignment | ( | int | row | ) | const |
Returns the alignment of row.
Definition at line 431 of file qgraphicsgridlayout.cpp.
References d, and Qt::Vertical.
int QGraphicsGridLayout::rowCount | ( | ) | const |
Returns the number of rows in the grid layout.
This is always one more than the index of the last row that is occupied by a layout item (empty rows are counted except for those at the end).
Definition at line 480 of file qgraphicsgridlayout.cpp.
References d, and Qt::Vertical.
Referenced by itemAt().
qreal QGraphicsGridLayout::rowMaximumHeight | ( | int | row | ) | const |
Returns the maximum height for row, row.
Definition at line 333 of file qgraphicsgridlayout.cpp.
References d, Qt::MaximumSize, and Qt::Vertical.
qreal QGraphicsGridLayout::rowMinimumHeight | ( | int | row | ) | const |
Returns the minimum height for row, row.
Definition at line 295 of file qgraphicsgridlayout.cpp.
References d, Qt::MinimumSize, and Qt::Vertical.
qreal QGraphicsGridLayout::rowPreferredHeight | ( | int | row | ) | const |
Returns the preferred height for row, row.
Definition at line 314 of file qgraphicsgridlayout.cpp.
References d, Qt::PreferredSize, and Qt::Vertical.
qreal QGraphicsGridLayout::rowSpacing | ( | int | row | ) | const |
Returns the row spacing for row.
Definition at line 219 of file qgraphicsgridlayout.cpp.
References d, and Qt::Vertical.
int QGraphicsGridLayout::rowStretchFactor | ( | int | row | ) | const |
Returns the stretch factor for row.
Definition at line 257 of file qgraphicsgridlayout.cpp.
References d, and Qt::Vertical.
void QGraphicsGridLayout::setAlignment | ( | QGraphicsLayoutItem * | item, |
Qt::Alignment | alignment | ||
) |
Sets the alignment for item to alignment.
Definition at line 459 of file qgraphicsgridlayout.cpp.
References alignment, d, invalidate(), and item.
void QGraphicsGridLayout::setColumnAlignment | ( | int | column, |
Qt::Alignment | alignment | ||
) |
Sets the alignment for column to alignment.
Definition at line 440 of file qgraphicsgridlayout.cpp.
References alignment, d, Qt::Horizontal, and invalidate().
Sets the fixed width of column to width.
Definition at line 410 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), Qt::MaximumSize, and Qt::MinimumSize.
Sets the maximum width of column to width.
Definition at line 391 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), and Qt::MaximumSize.
Sets the minimum width for column to width.
Definition at line 353 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), and Qt::MinimumSize.
Sets the preferred width for column to width.
Definition at line 372 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), and Qt::PreferredSize.
Sets the spacing for column to spacing.
Definition at line 228 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), and spacing.
void QGraphicsGridLayout::setColumnStretchFactor | ( | int | column, |
int | stretch | ||
) |
Sets the stretch factor for column to stretch.
Definition at line 266 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, and invalidate().
Sets the bounding geometry of the grid layout to rect.
Reimplemented from QGraphicsLayoutItem.
Definition at line 606 of file qgraphicsgridlayout.cpp.
References QRectF::adjust(), d, QGraphicsLayoutItem::geometry(), QGraphicsLayout::getContentsMargins(), qDebug, qSwap(), rect, Qt::RightToLeft, and QGraphicsLayoutItem::setGeometry().
Sets the default horizontal spacing for the grid layout to spacing.
Definition at line 158 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), and spacing.
void QGraphicsGridLayout::setRowAlignment | ( | int | row, |
Qt::Alignment | alignment | ||
) |
Sets the alignment of row to alignment.
Definition at line 421 of file qgraphicsgridlayout.cpp.
References alignment, d, invalidate(), and Qt::Vertical.
Sets the fixed height for row, row, to height.
Definition at line 342 of file qgraphicsgridlayout.cpp.
References d, invalidate(), Qt::MaximumSize, Qt::MinimumSize, and Qt::Vertical.
Sets the maximum height for row, row, to height.
Definition at line 323 of file qgraphicsgridlayout.cpp.
References d, invalidate(), Qt::MaximumSize, and Qt::Vertical.
Sets the minimum height for row, row, to height.
Definition at line 285 of file qgraphicsgridlayout.cpp.
References d, invalidate(), Qt::MinimumSize, and Qt::Vertical.
Sets the preferred height for row, row, to height.
Definition at line 304 of file qgraphicsgridlayout.cpp.
References d, invalidate(), Qt::PreferredSize, and Qt::Vertical.
Sets the spacing for row to spacing.
Definition at line 209 of file qgraphicsgridlayout.cpp.
References d, invalidate(), spacing, and Qt::Vertical.
void QGraphicsGridLayout::setRowStretchFactor | ( | int | row, |
int | stretch | ||
) |
Sets the stretch factor for row to stretch.
Definition at line 247 of file qgraphicsgridlayout.cpp.
References d, invalidate(), and Qt::Vertical.
Sets the grid layout's default spacing, both vertical and horizontal, to spacing.
Definition at line 199 of file qgraphicsgridlayout.cpp.
References d, Qt::Horizontal, invalidate(), spacing, and Qt::Vertical.
Sets the default vertical spacing for the grid layout to spacing.
Definition at line 177 of file qgraphicsgridlayout.cpp.
References d, invalidate(), spacing, and Qt::Vertical.
|
overridevirtual |
\reimp
Implements QGraphicsLayoutItem.
Definition at line 632 of file qgraphicsgridlayout.cpp.
References d, and QGraphicsLayout::getContentsMargins().
qreal QGraphicsGridLayout::verticalSpacing | ( | ) | const |
Returns the default vertical spacing for the grid layout.
Definition at line 187 of file qgraphicsgridlayout.cpp.
References d, and Qt::Vertical.