Skip to content

PythonQt.Qt.QGridLayout

QGridLayout

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QGridLayout takes the space made available to it (by its parent layout or by the parentWidget()), divides it up into rows and columns, and puts each widget it manages into the correct cell.

Columns and rows behave identically; we will discuss columns, but there are equivalent functions for rows.

Each column has a minimum width and a stretch factor. The minimum width is the greatest of that set using setColumnMinimumWidth() and the minimum width of each widget in that column. The stretch factor is set using setColumnStretch() and determines how much of the available space the column will get over and above its necessary minimum.

Normally, each managed widget or layout is put into a cell of its own using addWidget(). It is also possible for a widget to occupy multiple cells using the row and column spanning overloads of addItem() and addWidget(). If you do this, QGridLayout will guess how to distribute the size over the columns/rows (based on the stretch factors).

To remove a widget from a layout, call removeWidget(). Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.

This illustration shows a fragment of a dialog with a five-column, three-row grid (the grid is shown overlaid in magenta):

A grid layout

Columns 0, 2 and 4 in this dialog fragment are made up of a QLabel, a QLineEdit, and a QListBox. Columns 1 and 3 are placeholders made with setColumnMinimumWidth(). Row 0 consists of three QLabel objects, row 1 of three QLineEdit objects and row 2 of three QListBox objects. We used placeholder columns (1 and 3) to get the right amount of space between the columns.

Note that the columns and rows are not equally wide or tall. If you want two columns to have the same width, you must set their minimum widths and stretch factors to be the same yourself. You do this using setColumnMinimumWidth() and setColumnStretch().

If the QGridLayout is not the top-level layout (i.e. does not manage all of the widget's area and children), you must add it to its parent layout when you create it, but before you do anything with it. The normal way to add a layout is by calling addLayout() on the parent layout.

Once you have added your layout you can start putting widgets and other layouts into the cells of your grid layout using addWidget(), addItem(), and addLayout().

QGridLayout also includes two margin widths: the contents margin and the spacing(). The contents margin is the width of the reserved space along each of the QGridLayout's four sides. The spacing() is the width of the automatically allocated spacing between neighboring boxes.

The default contents margin values are provided by the style. The default value Qt styles specify is 9 for child widgets and 11 for windows. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout.

Source: https://doc.qt.io/archives/qt-5.15/qgridlayout.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
SetDefaultConstraint attribute Any (shared captured text)
SetFixedSize attribute Any (shared captured text)
SetMaximumSize attribute Any (shared captured text)
SetMinAndMaxSize attribute Any (shared captured text)
SetMinimumSize attribute Any (shared captured text)
SetNoConstraint attribute Any (shared captured text)
SizeConstraint attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
activate function (self) -> bool X.activate() -> bool (shared captured text)
addChildLayout function (self, l: Any) -> Any (shared captured text)
addChildWidget function (self, w: Any) -> Any (shared captured text)
addItem function (self, arg__1: Any) -> None Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it according to alignment. (shared captured text)
addLayout function (self, arg__1: Any, row: int, column: int, rowSpan: Any, columnSpan: Any, arg__6: Any) -> None X.addLayout(arg__1, row, column, rowSpan, columnSpan, arg__6) (shared captured text)
addWidget function (self, arg__1: Any, row: Any, column: Any, rowSpan: Any, columnSpan: Any, arg__6: Any) -> None X.addWidget(arg__1, row, column, rowSpan, columnSpan, arg__6) (shared captured text)
adoptLayout function (self, layout: Any) -> bool X.adoptLayout(layout) -> bool (shared captured text)
alignment function (self) -> Any (shared captured text)
alignmentRect function (self, arg__1: Any) -> Any X.alignmentRect(arg__1) -> PythonQt.QtCore.QRect (shared captured text)
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
cellRect function (self, row: int, column: int) -> Any X.cellRect(row, column) -> PythonQt.QtCore.QRect (shared captured text)
childEvent function (self, e: Any) -> Any (shared captured text)
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
closestAcceptableSize function (self, w: Any, s: Any) -> Any X.closestAcceptableSize(w, s) -> PythonQt.QtCore.QSize (shared captured text)
columnCount function (self) -> int X.columnCount() -> int (shared captured text)
columnMinimumWidth function (self, column: int) -> int X.columnMinimumWidth(column) -> int (shared captured text)
columnStretch function (self, column: int) -> int X.columnStretch(column) -> int (shared captured text)
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
contentsMargins function (self) -> Any X.contentsMargins() -> PythonQt.QtGui.QMargins (shared captured text)
contentsRect function (self) -> Any X.contentsRect() -> PythonQt.QtCore.QRect (shared captured text)
controlTypes function (self) -> Any (shared captured text)
count function (self) -> int X.count() -> int (shared captured text)
customEvent function (self, event: Any) -> Any (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QGridLayout.destroyed; argument details are not documented.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
event function (self, event: Any) -> bool X.event(event) -> bool (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
expandingDirections function (self) -> Any Reimplements: [QLayout::expandingDirections](https://doc.qt.io/archives/qt-5.15/qlayout.html#expandingDirections)() const. (shared captured text)
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
geometry function (self) -> Any X.geometry() -> PythonQt.QtCore.QRect (shared captured text)
hasHeightForWidth function (self) -> bool X.hasHeightForWidth() -> bool (shared captured text)
heightForWidth function (self, arg__1: int) -> int X.heightForWidth(arg__1) -> int (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
horizontalSpacing function (self) -> int X.horizontalSpacing() -> int (shared captured text)
indexOf function (self, arg__1: Any) -> int X.indexOf(arg__1) -> int (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
invalidate function (self) -> None Reimplements: [QLayout::invalidate](https://doc.qt.io/archives/qt-5.15/qlayout.html#invalidate)(). (shared captured text)
isEmpty function (self) -> bool X.isEmpty() -> bool (shared captured text)
isEnabled function (self) -> bool X.isEnabled() -> bool (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
itemAt function (self, index: int) -> Any X.itemAt(index) -> PythonQt.QtGui.QLayoutItem (shared captured text)
itemAtPosition function (self, row: int, column: int) -> Any X.itemAtPosition(row, column) -> PythonQt.QtGui.QLayoutItem (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
layout function (self) -> Any X.layout() -> PythonQt.QtGui.QLayout (shared captured text)
margin attribute Any (shared captured text)
maximumSize function (self) -> Any X.maximumSize() -> PythonQt.QtCore.QSize (shared captured text)
menuBar function (self) -> Any X.menuBar() -> PythonQt.QtGui.QWidget (shared captured text)
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
minimumHeightForWidth function (self, arg__1: int) -> int X.minimumHeightForWidth(arg__1) -> int (shared captured text)
minimumSize function (self) -> Any X.minimumSize() -> PythonQt.QtCore.QSize (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QGridLayout.objectNameChanged; argument details are not documented.
originCorner function (self) -> Any Returns the corner that's used for the grid's origin, i.e. for position (0, 0). (shared captured text)
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
parentWidget function (self) -> Any X.parentWidget() -> PythonQt.QtGui.QWidget (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
removeItem function (self, arg__1: Any) -> Any (shared captured text)
removeWidget function (self, w: Any) -> Any (shared captured text)
replaceWidget function (self, *args: Any, **kwargs: Any) -> Any X.replaceWidget(from, to, options) -> PythonQt.QtGui.QLayoutItem (shared captured text)
rowCount function (self) -> int X.rowCount() -> int (shared captured text)
rowMinimumHeight function (self, row: int) -> int X.rowMinimumHeight(row) -> int (shared captured text)
rowStretch function (self, row: int) -> int X.rowStretch(row) -> int (shared captured text)
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setAlignment function (self, l: Any, alignment: Any) -> bool X.setAlignment(l, alignment) -> bool (shared captured text)
setColumnMinimumWidth function (self, column: int, minSize: int) -> None X.setColumnMinimumWidth(column, minSize) (shared captured text)
setColumnStretch function (self, column: int, stretch: int) -> None X.setColumnStretch(column, stretch) (shared captured text)
setContentsMargins function (self, left: Any, top: Any, right: Any, bottom: Any) -> Any X.setContentsMargins(left, top, right, bottom) (shared captured text)
setDefaultPositioning function (self, n: int, orient: Any) -> None X.setDefaultPositioning(n, orient) (shared captured text)
setEnabled function (self, arg__1: Any) -> Any (shared captured text)
setGeometry function (self, arg__1: Any) -> None Reimplements: [QLayout::setGeometry](https://doc.qt.io/archives/qt-5.15/qlayout.html#setGeometry)(const QRect \&r). (shared captured text)
setHorizontalSpacing function (self, spacing: int) -> None (shared captured text)
setMargin function (self, arg__1: Any) -> Any (shared captured text)
setMenuBar function (self, w: Any) -> Any (shared captured text)
setObjectName function (self, name: Any) -> Any (shared captured text)
setOriginCorner function (self, arg__1: Any) -> None Sets the grid's origin corner, i.e. position (0, 0), to corner. (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setRowMinimumHeight function (self, row: int, minSize: int) -> None X.setRowMinimumHeight(row, minSize) (shared captured text)
setRowStretch function (self, row: int, stretch: int) -> None X.setRowStretch(row, stretch) (shared captured text)
setSizeConstraint function (self, arg__1: Any) -> Any (shared captured text)
setSpacing function (self, spacing: int) -> None This function sets both the vertical and horizontal spacing to spacing. (shared captured text)
setVerticalSpacing function (self, spacing: int) -> None (shared captured text)
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
sizeConstraint attribute Any (shared captured text)
sizeHint function (self) -> Any X.sizeHint() -> PythonQt.QtCore.QSize (shared captured text)
spacerItem function (self) -> Any X.spacerItem() -> PythonQt.QtGui.QSpacerItem (shared captured text)
spacing attribute int If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwise it return -1. (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
takeAt function (self, index: int) -> Any X.takeAt(index) -> PythonQt.QtGui.QLayoutItem (shared captured text)
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
totalHeightForWidth function (self, w: Any) -> int X.totalHeightForWidth(w) -> int (shared captured text)
totalMaximumSize function (self) -> Any X.totalMaximumSize() -> PythonQt.QtCore.QSize (shared captured text)
totalMinimumSize function (self) -> Any X.totalMinimumSize() -> PythonQt.QtCore.QSize (shared captured text)
totalSizeHint function (self) -> Any X.totalSizeHint() -> PythonQt.QtCore.QSize (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)
update function (self) -> Any (shared captured text)
verticalSpacing function (self) -> int X.verticalSpacing() -> int (shared captured text)
widget function (self) -> Any X.widget() -> PythonQt.QtGui.QWidget (shared captured text)
widgetEvent function (self, arg__1: Any) -> Any (shared captured text)