QGraphicsGridLayout

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

Inheritance diagram of PySide2.QtWidgets.QGraphicsGridLayout

Synopsis

Functions

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 setLayout() . QGraphicsGridLayout automatically computes the dimensions of the grid as you add items.

scene = QGraphicsScene()
textEdit = scene.addWidget(QTextEdit())
pushButton = scene.addWidget(QPushButton())

layout = QGraphicsGridLayout()
layout.addItem(textEdit, 0, 0)
layout.addItem(pushButton, 0, 1)

form = QGraphicsWidget()
form.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 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.

class QGraphicsGridLayout([parent=None])
param parent

QGraphicsLayoutItem

Constructs a QGraphicsGridLayout instance. parent is passed to QGraphicsLayout ‘s constructor.

PySide2.QtWidgets.QGraphicsGridLayout.addItem(item, row, column[, alignment=Qt.Alignment()])
Parameters

Adds item to the grid on row and column . You can specify an optional alignment for item .

PySide2.QtWidgets.QGraphicsGridLayout.addItem(item, row, column, rowSpan, columnSpan[, alignment=Qt.Alignment()])
Parameters
  • itemQGraphicsLayoutItem

  • rowint

  • columnint

  • rowSpanint

  • columnSpanint

  • alignmentAlignment

Adds item to the grid on row and column . You can specify a rowSpan and columnSpan and an optional alignment .

PySide2.QtWidgets.QGraphicsGridLayout.alignment(item)
Parameters

itemQGraphicsLayoutItem

Return type

Alignment

Returns the alignment for item .

See also

setAlignment()

PySide2.QtWidgets.QGraphicsGridLayout.columnAlignment(column)
Parameters

columnint

Return type

Alignment

Returns the alignment for column .

PySide2.QtWidgets.QGraphicsGridLayout.columnCount()
Return type

int

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).

PySide2.QtWidgets.QGraphicsGridLayout.columnMaximumWidth(column)
Parameters

columnint

Return type

qreal

Returns the maximum width for column .

PySide2.QtWidgets.QGraphicsGridLayout.columnMinimumWidth(column)
Parameters

columnint

Return type

qreal

Returns the minimum width for column .

PySide2.QtWidgets.QGraphicsGridLayout.columnPreferredWidth(column)
Parameters

columnint

Return type

qreal

Returns the preferred width for column .

PySide2.QtWidgets.QGraphicsGridLayout.columnSpacing(column)
Parameters

columnint

Return type

qreal

Returns the column spacing for column .

PySide2.QtWidgets.QGraphicsGridLayout.columnStretchFactor(column)
Parameters

columnint

Return type

int

Returns the stretch factor for column .

PySide2.QtWidgets.QGraphicsGridLayout.horizontalSpacing()
Return type

qreal

Returns the default horizontal spacing for the grid layout.

PySide2.QtWidgets.QGraphicsGridLayout.itemAt(row, column)
Parameters
  • rowint

  • columnint

Return type

QGraphicsLayoutItem

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

PySide2.QtWidgets.QGraphicsGridLayout.removeItem(item)
Parameters

itemQGraphicsLayoutItem

Removes the layout item item without destroying it. Ownership of the item is transferred to the caller.

See also

addItem()

PySide2.QtWidgets.QGraphicsGridLayout.rowAlignment(row)
Parameters

rowint

Return type

Alignment

Returns the alignment of row .

PySide2.QtWidgets.QGraphicsGridLayout.rowCount()
Return type

int

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).

PySide2.QtWidgets.QGraphicsGridLayout.rowMaximumHeight(row)
Parameters

rowint

Return type

qreal

Returns the maximum height for row, row .

PySide2.QtWidgets.QGraphicsGridLayout.rowMinimumHeight(row)
Parameters

rowint

Return type

qreal

Returns the minimum height for row, row .

PySide2.QtWidgets.QGraphicsGridLayout.rowPreferredHeight(row)
Parameters

rowint

Return type

qreal

Returns the preferred height for row, row .

PySide2.QtWidgets.QGraphicsGridLayout.rowSpacing(row)
Parameters

rowint

Return type

qreal

Returns the row spacing for row .

See also

setRowSpacing()

PySide2.QtWidgets.QGraphicsGridLayout.rowStretchFactor(row)
Parameters

rowint

Return type

int

Returns the stretch factor for row .

PySide2.QtWidgets.QGraphicsGridLayout.setAlignment(item, alignment)
Parameters

Sets the alignment for item to alignment .

See also

alignment()

PySide2.QtWidgets.QGraphicsGridLayout.setColumnAlignment(column, alignment)
Parameters
  • columnint

  • alignmentAlignment

Sets the alignment for column to alignment .

PySide2.QtWidgets.QGraphicsGridLayout.setColumnFixedWidth(column, width)
Parameters
  • columnint

  • widthqreal

Sets the fixed width of column to width .

PySide2.QtWidgets.QGraphicsGridLayout.setColumnMaximumWidth(column, width)
Parameters
  • columnint

  • widthqreal

Sets the maximum width of column to width .

PySide2.QtWidgets.QGraphicsGridLayout.setColumnMinimumWidth(column, width)
Parameters
  • columnint

  • widthqreal

Sets the minimum width for column to width .

PySide2.QtWidgets.QGraphicsGridLayout.setColumnPreferredWidth(column, width)
Parameters
  • columnint

  • widthqreal

Sets the preferred width for column to width .

PySide2.QtWidgets.QGraphicsGridLayout.setColumnSpacing(column, spacing)
Parameters
  • columnint

  • spacingqreal

Sets the spacing for column to spacing .

See also

columnSpacing()

PySide2.QtWidgets.QGraphicsGridLayout.setColumnStretchFactor(column, stretch)
Parameters
  • columnint

  • stretchint

Sets the stretch factor for column to stretch .

PySide2.QtWidgets.QGraphicsGridLayout.setHorizontalSpacing(spacing)
Parameters

spacingqreal

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

PySide2.QtWidgets.QGraphicsGridLayout.setRowAlignment(row, alignment)
Parameters
  • rowint

  • alignmentAlignment

Sets the alignment of row to alignment .

See also

rowAlignment()

PySide2.QtWidgets.QGraphicsGridLayout.setRowFixedHeight(row, height)
Parameters
  • rowint

  • heightqreal

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

PySide2.QtWidgets.QGraphicsGridLayout.setRowMaximumHeight(row, height)
Parameters
  • rowint

  • heightqreal

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

PySide2.QtWidgets.QGraphicsGridLayout.setRowMinimumHeight(row, height)
Parameters
  • rowint

  • heightqreal

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

PySide2.QtWidgets.QGraphicsGridLayout.setRowPreferredHeight(row, height)
Parameters
  • rowint

  • heightqreal

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

PySide2.QtWidgets.QGraphicsGridLayout.setRowSpacing(row, spacing)
Parameters
  • rowint

  • spacingqreal

Sets the spacing for row to spacing .

See also

rowSpacing()

PySide2.QtWidgets.QGraphicsGridLayout.setRowStretchFactor(row, stretch)
Parameters
  • rowint

  • stretchint

Sets the stretch factor for row to stretch .

PySide2.QtWidgets.QGraphicsGridLayout.setSpacing(spacing)
Parameters

spacingqreal

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

PySide2.QtWidgets.QGraphicsGridLayout.setVerticalSpacing(spacing)
Parameters

spacingqreal

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

PySide2.QtWidgets.QGraphicsGridLayout.verticalSpacing()
Return type

qreal

Returns the default vertical spacing for the grid layout.