Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QGraphicsGridLayout Class Reference

The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View. More...

#include <qgraphicsgridlayout.h>

Inheritance diagram for QGraphicsGridLayout:
Collaboration diagram for QGraphicsGridLayout:

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.
QGraphicsLayoutItemitemAt (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.
QGraphicsLayoutItemitemAt (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
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 QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.

Since
4.4

\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 18 of file qgraphicsgridlayout.h.

Constructor & Destructor Documentation

◆ QGraphicsGridLayout()

QGraphicsGridLayout::QGraphicsGridLayout ( QGraphicsLayoutItem * parent = nullptr)

Constructs a QGraphicsGridLayout instance.

parent is passed to QGraphicsLayout's constructor.

Definition at line 91 of file qgraphicsgridlayout.cpp.

◆ ~QGraphicsGridLayout()

QGraphicsGridLayout::~QGraphicsGridLayout ( )
virtual

Destroys the QGraphicsGridLayout object.

Definition at line 99 of file qgraphicsgridlayout.cpp.

Member Function Documentation

◆ addItem() [1/2]

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 119 of file qgraphicsgridlayout.cpp.

◆ addItem() [2/2]

void QGraphicsGridLayout::addItem ( QGraphicsLayoutItem * item,
int row,
int column,
Qt::Alignment alignment = Qt::Alignment() )
inline

Adds item to the grid on row and column.

You can specify an optional alignment for item.

Definition at line 94 of file qgraphicsgridlayout.h.

◆ alignment()

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

Returns the alignment for item.

Definition at line 470 of file qgraphicsgridlayout.cpp.

◆ columnAlignment()

Qt::Alignment QGraphicsGridLayout::columnAlignment ( int column) const

Returns the alignment for column.

Definition at line 451 of file qgraphicsgridlayout.cpp.

◆ columnCount()

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 492 of file qgraphicsgridlayout.cpp.

◆ columnMaximumWidth()

qreal QGraphicsGridLayout::columnMaximumWidth ( int column) const

Returns the maximum width for column.

Definition at line 402 of file qgraphicsgridlayout.cpp.

◆ columnMinimumWidth()

qreal QGraphicsGridLayout::columnMinimumWidth ( int column) const

Returns the minimum width for column.

Definition at line 364 of file qgraphicsgridlayout.cpp.

◆ columnPreferredWidth()

qreal QGraphicsGridLayout::columnPreferredWidth ( int column) const

Returns the preferred width for column.

Definition at line 383 of file qgraphicsgridlayout.cpp.

◆ columnSpacing()

qreal QGraphicsGridLayout::columnSpacing ( int column) const

Returns the column spacing for column.

Definition at line 239 of file qgraphicsgridlayout.cpp.

◆ columnStretchFactor()

int QGraphicsGridLayout::columnStretchFactor ( int column) const

Returns the stretch factor for column.

Definition at line 277 of file qgraphicsgridlayout.cpp.

◆ count()

int QGraphicsGridLayout::count ( ) const
overridevirtual

Returns the number of layout items in this grid layout.

Implements QGraphicsLayout.

Definition at line 516 of file qgraphicsgridlayout.cpp.

◆ horizontalSpacing()

qreal QGraphicsGridLayout::horizontalSpacing ( ) const

Returns the default horizontal spacing for the grid layout.

Definition at line 169 of file qgraphicsgridlayout.cpp.

◆ invalidate()

void QGraphicsGridLayout::invalidate ( )
overridevirtual

\reimp

Reimplemented from QGraphicsLayout.

Definition at line 586 of file qgraphicsgridlayout.cpp.

◆ itemAt() [1/2]

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

Returns the layout item at index, or \nullptr if there is no layout item at this index.

Implements QGraphicsLayout.

Definition at line 526 of file qgraphicsgridlayout.cpp.

◆ itemAt() [2/2]

QGraphicsLayoutItem * QGraphicsGridLayout::itemAt ( int row,
int column ) const

Returns a pointer to the layout item at (row, column).

Definition at line 501 of file qgraphicsgridlayout.cpp.

◆ removeAt()

void QGraphicsGridLayout::removeAt ( int index)
overridevirtual

Removes the layout item at index without destroying it.

Ownership of the item is transferred to the caller.

See also
addItem()

Implements QGraphicsLayout.

Definition at line 544 of file qgraphicsgridlayout.cpp.

◆ removeItem()

void QGraphicsGridLayout::removeItem ( QGraphicsLayoutItem * item)

Removes the layout item item without destroying it.

Ownership of the item is transferred to the caller.

See also
addItem()

Definition at line 577 of file qgraphicsgridlayout.cpp.

◆ rowAlignment()

Qt::Alignment QGraphicsGridLayout::rowAlignment ( int row) const

Returns the alignment of row.

Definition at line 432 of file qgraphicsgridlayout.cpp.

◆ rowCount()

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 481 of file qgraphicsgridlayout.cpp.

◆ rowMaximumHeight()

qreal QGraphicsGridLayout::rowMaximumHeight ( int row) const

Returns the maximum height for row, row.

Definition at line 334 of file qgraphicsgridlayout.cpp.

◆ rowMinimumHeight()

qreal QGraphicsGridLayout::rowMinimumHeight ( int row) const

Returns the minimum height for row, row.

Definition at line 296 of file qgraphicsgridlayout.cpp.

◆ rowPreferredHeight()

qreal QGraphicsGridLayout::rowPreferredHeight ( int row) const

Returns the preferred height for row, row.

Definition at line 315 of file qgraphicsgridlayout.cpp.

◆ rowSpacing()

qreal QGraphicsGridLayout::rowSpacing ( int row) const

Returns the row spacing for row.

Definition at line 220 of file qgraphicsgridlayout.cpp.

◆ rowStretchFactor()

int QGraphicsGridLayout::rowStretchFactor ( int row) const

Returns the stretch factor for row.

Definition at line 258 of file qgraphicsgridlayout.cpp.

◆ setAlignment()

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

Sets the alignment for item to alignment.

Definition at line 460 of file qgraphicsgridlayout.cpp.

◆ setColumnAlignment()

void QGraphicsGridLayout::setColumnAlignment ( int column,
Qt::Alignment alignment )

Sets the alignment for column to alignment.

Definition at line 441 of file qgraphicsgridlayout.cpp.

◆ setColumnFixedWidth()

void QGraphicsGridLayout::setColumnFixedWidth ( int column,
qreal width )

Sets the fixed width of column to width.

Definition at line 411 of file qgraphicsgridlayout.cpp.

◆ setColumnMaximumWidth()

void QGraphicsGridLayout::setColumnMaximumWidth ( int column,
qreal width )

Sets the maximum width of column to width.

Definition at line 392 of file qgraphicsgridlayout.cpp.

◆ setColumnMinimumWidth()

void QGraphicsGridLayout::setColumnMinimumWidth ( int column,
qreal width )

Sets the minimum width for column to width.

Definition at line 354 of file qgraphicsgridlayout.cpp.

◆ setColumnPreferredWidth()

void QGraphicsGridLayout::setColumnPreferredWidth ( int column,
qreal width )

Sets the preferred width for column to width.

Definition at line 373 of file qgraphicsgridlayout.cpp.

◆ setColumnSpacing()

void QGraphicsGridLayout::setColumnSpacing ( int column,
qreal spacing )

Sets the spacing for column to spacing.

Definition at line 229 of file qgraphicsgridlayout.cpp.

◆ setColumnStretchFactor()

void QGraphicsGridLayout::setColumnStretchFactor ( int column,
int stretch )

Sets the stretch factor for column to stretch.

Definition at line 267 of file qgraphicsgridlayout.cpp.

◆ setGeometry()

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

Sets the bounding geometry of the grid layout to rect.

Reimplemented from QGraphicsLayoutItem.

Definition at line 607 of file qgraphicsgridlayout.cpp.

◆ setHorizontalSpacing()

void QGraphicsGridLayout::setHorizontalSpacing ( qreal spacing)

Sets the default horizontal spacing for the grid layout to spacing.

Definition at line 159 of file qgraphicsgridlayout.cpp.

◆ setRowAlignment()

void QGraphicsGridLayout::setRowAlignment ( int row,
Qt::Alignment alignment )

Sets the alignment of row to alignment.

Definition at line 422 of file qgraphicsgridlayout.cpp.

◆ setRowFixedHeight()

void QGraphicsGridLayout::setRowFixedHeight ( int row,
qreal height )

Sets the fixed height for row, row, to height.

Definition at line 343 of file qgraphicsgridlayout.cpp.

◆ setRowMaximumHeight()

void QGraphicsGridLayout::setRowMaximumHeight ( int row,
qreal height )

Sets the maximum height for row, row, to height.

Definition at line 324 of file qgraphicsgridlayout.cpp.

◆ setRowMinimumHeight()

void QGraphicsGridLayout::setRowMinimumHeight ( int row,
qreal height )

Sets the minimum height for row, row, to height.

Definition at line 286 of file qgraphicsgridlayout.cpp.

◆ setRowPreferredHeight()

void QGraphicsGridLayout::setRowPreferredHeight ( int row,
qreal height )

Sets the preferred height for row, row, to height.

Definition at line 305 of file qgraphicsgridlayout.cpp.

◆ setRowSpacing()

void QGraphicsGridLayout::setRowSpacing ( int row,
qreal spacing )

Sets the spacing for row to spacing.

Definition at line 210 of file qgraphicsgridlayout.cpp.

◆ setRowStretchFactor()

void QGraphicsGridLayout::setRowStretchFactor ( int row,
int stretch )

Sets the stretch factor for row to stretch.

Definition at line 248 of file qgraphicsgridlayout.cpp.

◆ setSpacing()

void QGraphicsGridLayout::setSpacing ( qreal spacing)

Sets the grid layout's default spacing, both vertical and horizontal, to spacing.

See also
rowSpacing(), columnSpacing()

Definition at line 200 of file qgraphicsgridlayout.cpp.

◆ setVerticalSpacing()

void QGraphicsGridLayout::setVerticalSpacing ( qreal spacing)

Sets the default vertical spacing for the grid layout to spacing.

Definition at line 178 of file qgraphicsgridlayout.cpp.

◆ sizeHint()

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

\reimp

Implements QGraphicsLayoutItem.

Definition at line 633 of file qgraphicsgridlayout.cpp.

◆ verticalSpacing()

qreal QGraphicsGridLayout::verticalSpacing ( ) const

Returns the default vertical spacing for the grid layout.

Definition at line 188 of file qgraphicsgridlayout.cpp.


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