QGraphicsGridLayout Class▲
-
Header: QGraphicsGridLayout
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
-
qmake: QT += widgets
-
Inherits: QGraphicsLayout
-
Group: QGraphicsGridLayout is part of graphicsview-api
Detailed Description▲
The most common way to use QGraphicsGridLayout is to construct an object on the heap with no parent, add widgets and layouts by calling addItem(), and finally assign the layout to a widget by calling QGraphicsWidget::setLayout(). QGraphicsGridLayout automatically computes the dimensions of the grid as you add items.
QGraphicsScene scene;
QGraphicsWidget *
textEdit =
scene.addWidget(new
QTextEdit);
QGraphicsWidget *
pushButton =
scene.addWidget(new
QPushButton);
QGraphicsGridLayout *
layout =
new
QGraphicsGridLayout;
layout-&
gt;addItem(textEdit, 0
, 0
);
layout-&
gt;addItem(pushButton, 0
, 1
);
QGraphicsWidget *
form =
new
QGraphicsWidget;
form-&
gt;setLayout(layout);
scene.addItem(form);
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.
Size Hints and Size Policies in QGraphicsGridLayout▲
QGraphicsGridLayout respects each item's size hints and size policies, and when a cell in the grid has more space than the items can fill, each item is arranged according to the layout's alignment for that item. You can set an alignment for each item by calling setAlignment(), and check the alignment for any item by calling alignment(). You can also set the alignment for an entire row or column by calling setRowAlignment() and setColumnAlignment() respectively. By default, items are aligned to the top left.
See Also▲
See also QGraphicsLinearLayout, QGraphicsWidget
Member Function Documentation▲
QGraphicsGridLayout::QGraphicsGridLayout(QGraphicsLayoutItem *parent = nullptr)▲
Constructs a QGraphicsGridLayout instance. parent is passed to QGraphicsLayout's constructor.
[virtual] QGraphicsGridLayout::~QGraphicsGridLayout()▲
Destroys the QGraphicsGridLayout object.
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.
void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = Qt::Alignment())▲
Adds item to the grid on row and column. You can specify an optional alignment for item.
Qt::Alignment QGraphicsGridLayout::alignment(QGraphicsLayoutItem *item) const▲
Qt::Alignment QGraphicsGridLayout::columnAlignment(int column) const▲
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).
qreal QGraphicsGridLayout::columnMaximumWidth(int column) const▲
qreal QGraphicsGridLayout::columnMinimumWidth(int column) const▲
qreal QGraphicsGridLayout::columnPreferredWidth(int column) const▲
qreal QGraphicsGridLayout::columnSpacing(int column) const▲
int QGraphicsGridLayout::columnStretchFactor(int column) const▲
[override virtual] int QGraphicsGridLayout::count() const▲
Reimplements: QGraphicsLayout::count() const.
Returns the number of layout items in this grid layout.
qreal QGraphicsGridLayout::horizontalSpacing() const▲
Returns the default horizontal spacing for the grid layout.
See Also▲
See also setHorizontalSpacing()
[override virtual] void QGraphicsGridLayout::invalidate()▲
Reimplements: QGraphicsLayout::invalidate().
QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const▲
Returns a pointer to the layout item at (row, column).
[override virtual] QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const▲
Reimplements: QGraphicsLayout::itemAt(int i) const.
Returns the layout item at index, or nullptr if there is no layout item at this index.
[override virtual] void QGraphicsGridLayout::removeAt(int index)▲
Reimplements: QGraphicsLayout::removeAt(int index).
Removes the layout item at index without destroying it. Ownership of the item is transferred to the caller.
See Also▲
See also addItem()
void QGraphicsGridLayout::removeItem(QGraphicsLayoutItem *item)▲
Removes the layout item item without destroying it. Ownership of the item is transferred to the caller.
See Also▲
See also addItem()
Qt::Alignment QGraphicsGridLayout::rowAlignment(int row) const▲
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).
qreal QGraphicsGridLayout::rowMaximumHeight(int row) const▲
qreal QGraphicsGridLayout::rowMinimumHeight(int row) const▲
qreal QGraphicsGridLayout::rowPreferredHeight(int row) const▲
qreal QGraphicsGridLayout::rowSpacing(int row) const▲
int QGraphicsGridLayout::rowStretchFactor(int row) const▲
void QGraphicsGridLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)▲
void QGraphicsGridLayout::setColumnAlignment(int column, Qt::Alignment alignment)▲
void QGraphicsGridLayout::setColumnFixedWidth(int column, qreal width)▲
Sets the fixed width of column to width.
void QGraphicsGridLayout::setColumnMaximumWidth(int column, qreal width)▲
void QGraphicsGridLayout::setColumnMinimumWidth(int column, qreal width)▲
void QGraphicsGridLayout::setColumnPreferredWidth(int column, qreal width)▲
void QGraphicsGridLayout::setColumnSpacing(int column, qreal spacing)▲
void QGraphicsGridLayout::setColumnStretchFactor(int column, int stretch)▲
[override virtual] void QGraphicsGridLayout::setGeometry(const QRectF &rect)▲
Reimplements: QGraphicsLayoutItem::setGeometry(const QRectF &rect).
Sets the bounding geometry of the grid layout to rect.
void QGraphicsGridLayout::setHorizontalSpacing(qreal spacing)▲
Sets the default horizontal spacing for the grid layout to spacing.
See Also▲
See also horizontalSpacing()
void QGraphicsGridLayout::setRowAlignment(int row, Qt::Alignment alignment)▲
void QGraphicsGridLayout::setRowFixedHeight(int row, qreal height)▲
Sets the fixed height for row, row, to height.
void QGraphicsGridLayout::setRowMaximumHeight(int row, qreal height)▲
void QGraphicsGridLayout::setRowMinimumHeight(int row, qreal height)▲
void QGraphicsGridLayout::setRowPreferredHeight(int row, qreal height)▲
void QGraphicsGridLayout::setRowSpacing(int row, qreal spacing)▲
void QGraphicsGridLayout::setRowStretchFactor(int row, int stretch)▲
void QGraphicsGridLayout::setSpacing(qreal spacing)▲
Sets the grid layout's default spacing, both vertical and horizontal, to spacing.
See Also▲
See also rowSpacing(), columnSpacing()
void QGraphicsGridLayout::setVerticalSpacing(qreal spacing)▲
Sets the default vertical spacing for the grid layout to spacing.
See Also▲
See also verticalSpacing()