|  | Home · All Classes · Modules

# QGraphicsGridLayout Class Reference
[QtGui module]

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

Inherits QGraphicsLayout.

### Methods

- __init__ (self, QGraphicsLayoutItem parent = None)
- addItem (self, QGraphicsLayoutItem, int, int, int, int, Qt.Alignment alignment = 0)
- addItem (self, QGraphicsLayoutItem, int, int, Qt.Alignment alignment = 0)
- Qt.Alignment alignment (self, QGraphicsLayoutItem)
- Qt.Alignment columnAlignment (self, int)
- int columnCount (self)
- float columnMaximumWidth (self, int)
- float columnMinimumWidth (self, int)
- float columnPreferredWidth (self, int)
- float columnSpacing (self, int)
- int columnStretchFactor (self, int)
- int count (self)
- float horizontalSpacing (self)
- invalidate (self)
- QGraphicsLayoutItem itemAt (self, int, int)
- QGraphicsLayoutItem itemAt (self, int)
- removeAt (self, int)
- Qt.Alignment rowAlignment (self, int)
- int rowCount (self)
- float rowMaximumHeight (self, int)
- float rowMinimumHeight (self, int)
- float rowPreferredHeight (self, int)
- float rowSpacing (self, int)
- int rowStretchFactor (self, int)
- setAlignment (self, QGraphicsLayoutItem, Qt.Alignment)
- setColumnAlignment (self, int, Qt.Alignment)
- setColumnFixedWidth (self, int, float)
- setColumnMaximumWidth (self, int, float)
- setColumnMinimumWidth (self, int, float)
- setColumnPreferredWidth (self, int, float)
- setColumnSpacing (self, int, float)
- setColumnStretchFactor (self, int, int)
- setGeometry (self, QRectF)
- setHorizontalSpacing (self, float)
- setRowAlignment (self, int, Qt.Alignment)
- setRowFixedHeight (self, int, float)
- setRowMaximumHeight (self, int, float)
- setRowMinimumHeight (self, int, float)
- setRowPreferredHeight (self, int, float)
- setRowSpacing (self, int, float)
- setRowStretchFactor (self, int, int)
- setSpacing (self, float)
- setVerticalSpacing (self, float)
- QSizeF sizeHint (self, Qt.SizeHint, QSizeF constraint = QSizeF())
- float verticalSpacing (self)

## Detailed Description

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

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->addItem(textEdit, 0, 0);
     layout->addItem(pushButton, 0, 1);

     QGraphicsWidget *form = new 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 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.

See also QGraphicsLinearLayout and QGraphicsWidget.

## Method Documentation

### QGraphicsGridLayout.__init__ (self, QGraphicsLayoutItem parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

### QGraphicsGridLayout.addItem (self, QGraphicsLayoutItem, int, int, int, int, Qt.Alignment alignment = 0)

The QGraphicsLayoutItem argument has it's ownership transferred to Qt.

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

### QGraphicsGridLayout.addItem (self, QGraphicsLayoutItem, int, int, Qt.Alignment alignment = 0)

The QGraphicsLayoutItem argument, if not None, causes self to be owned by Qt instead of PyQt.

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

### Qt.Alignment QGraphicsGridLayout.alignment (self, QGraphicsLayoutItem)

Returns the alignment for item.

See also setAlignment().

### Qt.Alignment QGraphicsGridLayout.columnAlignment (self, int)

Returns the alignment for column.

See also setColumnAlignment().

### int QGraphicsGridLayout.columnCount (self)

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

### float QGraphicsGridLayout.columnMaximumWidth (self, int)

Returns the maximum width for column.

See also setColumnMaximumWidth().

### float QGraphicsGridLayout.columnMinimumWidth (self, int)

Returns the minimum width for column.

See also setColumnMinimumWidth().

### float QGraphicsGridLayout.columnPreferredWidth (self, int)

Returns the preferred width for column.

See also setColumnPreferredWidth().

### float QGraphicsGridLayout.columnSpacing (self, int)

Returns the column spacing for column.

See also setColumnSpacing().

### int QGraphicsGridLayout.columnStretchFactor (self, int)

Returns the stretch factor for column.

See also setColumnStretchFactor().

### int QGraphicsGridLayout.count (self)

Reimplemented from QGraphicsLayout.count().

Returns the number of layout items in this grid layout.

### float QGraphicsGridLayout.horizontalSpacing (self)

Returns the default horizontal spacing for the grid layout.

See also setHorizontalSpacing().

### QGraphicsGridLayout.invalidate (self)

Reimplemented from QGraphicsLayout.invalidate().

### QGraphicsLayoutItem QGraphicsGridLayout.itemAt (self, int, int)

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

### QGraphicsLayoutItem QGraphicsGridLayout.itemAt (self, int)

Reimplemented from QGraphicsLayout.itemAt().

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

### QGraphicsGridLayout.removeAt (self, int)

Reimplemented from QGraphicsLayout.removeAt().

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

See also addItem().

### Qt.Alignment QGraphicsGridLayout.rowAlignment (self, int)

Returns the alignment of row.

See also setRowAlignment().

### int QGraphicsGridLayout.rowCount (self)

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

### float QGraphicsGridLayout.rowMaximumHeight (self, int)

Returns the maximum height for row, row.

See also setRowMaximumHeight().

### float QGraphicsGridLayout.rowMinimumHeight (self, int)

Returns the minimum height for row, row.

See also setRowMinimumHeight().

### float QGraphicsGridLayout.rowPreferredHeight (self, int)

Returns the preferred height for row, row.

See also setRowPreferredHeight().

### float QGraphicsGridLayout.rowSpacing (self, int)

Returns the row spacing for row.

See also setRowSpacing().

### int QGraphicsGridLayout.rowStretchFactor (self, int)

Returns the stretch factor for row.

See also setRowStretchFactor().

### QGraphicsGridLayout.setAlignment (self, QGraphicsLayoutItem, Qt.Alignment)

Sets the alignment for item to alignment.

See also alignment().

### QGraphicsGridLayout.setColumnAlignment (self, int, Qt.Alignment)

Sets the alignment for column to alignment.

See also columnAlignment().

### QGraphicsGridLayout.setColumnFixedWidth (self, int, float)

Sets the fixed width of column to width.

### QGraphicsGridLayout.setColumnMaximumWidth (self, int, float)

Sets the maximum width of column to width.

See also columnMaximumWidth().

### QGraphicsGridLayout.setColumnMinimumWidth (self, int, float)

Sets the minimum width for column to width.

See also columnMinimumWidth().

### QGraphicsGridLayout.setColumnPreferredWidth (self, int, float)

Sets the preferred width for column to width.

See also columnPreferredWidth().

### QGraphicsGridLayout.setColumnSpacing (self, int, float)

Sets the spacing for column to spacing.

See also columnSpacing().

### QGraphicsGridLayout.setColumnStretchFactor (self, int, int)

Sets the stretch factor for column to stretch.

See also columnStretchFactor().

### QGraphicsGridLayout.setGeometry (self, QRectF)

Reimplemented from QGraphicsLayoutItem.setGeometry().

Sets the bounding geometry of the grid layout to rect.

### QGraphicsGridLayout.setHorizontalSpacing (self, float)

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

See also horizontalSpacing().

### QGraphicsGridLayout.setRowAlignment (self, int, Qt.Alignment)

Sets the alignment of row to alignment.

See also rowAlignment().

### QGraphicsGridLayout.setRowFixedHeight (self, int, float)

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

### QGraphicsGridLayout.setRowMaximumHeight (self, int, float)

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

See also rowMaximumHeight().

### QGraphicsGridLayout.setRowMinimumHeight (self, int, float)

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

See also rowMinimumHeight().

### QGraphicsGridLayout.setRowPreferredHeight (self, int, float)

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

See also rowPreferredHeight().

### QGraphicsGridLayout.setRowSpacing (self, int, float)

Sets the spacing for row to spacing.

See also rowSpacing().

### QGraphicsGridLayout.setRowStretchFactor (self, int, int)

Sets the stretch factor for row to stretch.

See also rowStretchFactor().

### QGraphicsGridLayout.setSpacing (self, float)

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

See also rowSpacing() and columnSpacing().

### QGraphicsGridLayout.setVerticalSpacing (self, float)

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

See also verticalSpacing().

### QSizeF QGraphicsGridLayout.sizeHint (self, Qt.SizeHint, QSizeF constraint = QSizeF())

Reimplemented from QGraphicsLayoutItem.sizeHint().

### float QGraphicsGridLayout.verticalSpacing (self)

Returns the default vertical spacing for the grid layout.

See also setVerticalSpacing().