Skip to content

Gtk.GridLayout

class — extends LayoutManager

Arranges child widgets in rows and columns.

Children have an "attach point" defined by the horizontal and vertical index of the cell they occupy; children can span multiple rows or columns. The layout properties for setting the attach points and spans are set using the GridLayoutChild associated to each child widget.

The behaviour of GtkGridLayout when several children occupy the same grid cell is undefined.

GtkGridLayout can be used like a GtkBoxLayout if all children are attached to the same row or column; however, if you only ever need a single row or column, you should consider using GtkBoxLayout.

Constructors

new

@classmethod
def new(cls) -> LayoutManager

Creates a new GtkGridLayout.

Methods

get_baseline_row

def get_baseline_row(self) -> int

Retrieves the row set with GridLayout.set_baseline_row.

get_column_homogeneous

def get_column_homogeneous(self) -> bool

Checks whether all columns of grid should have the same width.

get_column_spacing

def get_column_spacing(self) -> int

Retrieves the spacing set with GridLayout.set_column_spacing.

get_row_baseline_position

def get_row_baseline_position(self, row: int) -> BaselinePosition

Returns the baseline position of row.

If no value has been set with GridLayout.set_row_baseline_position, the default value of BaselinePosition.CENTER is returned.

Parameters:

  • row — a row index

get_row_homogeneous

def get_row_homogeneous(self) -> bool

Checks whether all rows of grid should have the same height.

get_row_spacing

def get_row_spacing(self) -> int

Retrieves the spacing set with GridLayout.set_row_spacing.

set_baseline_row

def set_baseline_row(self, row: int) -> None

Sets which row defines the global baseline for the entire grid.

Each row in the grid can have its own local baseline, but only one of those is global, meaning it will be the baseline in the parent of the grid.

Parameters:

  • row — the row index

set_column_homogeneous

def set_column_homogeneous(self, homogeneous: bool) -> None

Sets whether all columns of grid should have the same width.

Parameters:

  • homogeneousTrue to make columns homogeneous

set_column_spacing

def set_column_spacing(self, spacing: int) -> None

Sets the amount of space to insert between consecutive columns.

Parameters:

  • spacing — the amount of space between columns, in pixels

set_row_baseline_position

def set_row_baseline_position(self, row: int, pos: BaselinePosition | int) -> None

Sets how the baseline should be positioned on row of the grid, in case that row is assigned more space than is requested.

Parameters:

  • row — a row index
  • pos — a GtkBaselinePosition

set_row_homogeneous

def set_row_homogeneous(self, homogeneous: bool) -> None

Sets whether all rows of grid should have the same height.

Parameters:

  • homogeneousTrue to make rows homogeneous

set_row_spacing

def set_row_spacing(self, spacing: int) -> None

Sets the amount of space to insert between consecutive rows.

Parameters:

  • spacing — the amount of space between rows, in pixels

Properties

baseline_row

baseline_row: int  # read/write

The row to align to the baseline, when GtkWidget:valign is set to Align.BASELINE.

column_homogeneous

column_homogeneous: bool  # read/write

Whether all the columns in the grid have the same width.

column_spacing

column_spacing: int  # read/write

The amount of space between to consecutive columns.

row_homogeneous

row_homogeneous: bool  # read/write

Whether all the rows in the grid have the same height.

row_spacing

row_spacing: int  # read/write

The amount of space between to consecutive rows.