grid_renderer.*

Provides

  • func

    painter_save: Context manager saving and restoring painter state

  • func

    painter_zoom: Context manager scaling and restoring the painter

  • func

    painter_rotate: Context manager rotating and restoring the painter

  • GridCellNavigator: Find neighbors of a cell

  • EdgeBorders: Dataclass for edge properties

  • CellEdgeRenderer: Paints cell edges

  • QColorCache: QColor cache

  • CellRenderer: Paints cells

class grid_renderer.CellEdgeRenderer(painter, center, borders)[source]

Bases: object

Paints cell edges

Borders are provided by EdgeBorders in order: left, right, top, bottom

Parameters
  • painter (QPainter) – Painter with which edge is drawn

  • center (QPointF) – Edge center

  • borders (EdgeBorders) – Border widths and colors

paint()[source]

Paints the edge

class grid_renderer.CellRenderer(grid, painter, option, index)[source]

Bases: object

Paints cells

Cell rendering governs the area of a cell inside its borders. It is done in a vector oriented way. Therefore, the following conventions shall apply:

  • Cell borders of width 1 shall be painted so that they appear only in the bottom and right edge of the cell.

  • Cell borders of all widths have the same center line.

  • Cell borders that are thicker than 1 are painted on all borders.

  • At the edges, borders are painted in the following order:
    1. Thin borders are painted first

    2. If border width is equal, lighter colors are painted first

Parameters
  • grid (QTableView) – The main grid widget

  • painter (QPainter) – Painter with which borders are drawn

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell to be rendered

inner_rect(rect)[source]

Returns inner rect that is shrunk by border widths

For merged cells, minimum top/left border widths are taken into account

Parameters

rect (QRectF) – Cell rect to be shrunk

Return type

QRectF

paint()[source]

Paints the cell

paint_above_borders(rect)[source]

Paint lower borders of all above cells

Parameters

rect (QRectF) – Cell rect of below cell, in which the borders are painted

paint_borders(rect)[source]

Paint cell borders

paint_bottom_border(rect)[source]

Paint bottom border of cell

Parameters

rect (QRectF) – Cell rect of the cell to be painted

paint_bottom_left_edge(rect)[source]

Paints bottom left edge of the cell

Parameters

rect (QRectF) –

Cell rect of cell, for which the edge is painted

top

L | C

left ———— right
BL | B

bottom

paint_bottom_right_edge(rect)[source]

Paints bottom right edge of the cell

Parameters

rect (QRectF) –

Cell rect of cell, for which the edge is painted

top

C | R

left ———– right
B | BR

bottom

paint_content(rect)[source]
Parameters

rect (QRectF) – Cell rect of the cell to be painted

paint_left_borders(rect)[source]

Paint right borders of all left cells

Parameters

rect (QRectF) – Cell rect of right cell, in which the borders are painted

paint_right_border(rect)[source]

Paint right border of cell

Parameters

rect (QRectF) – Cell rect of the cell to be painted

paint_top_left_edge(rect)[source]

Paints top left edge of the cell

Parameters

rect (QRectF) –

Cell rect of cell, for which the edge is painted

top

TL | T

left ———— right
L | C

bottom

paint_top_right_edge(rect)[source]

Paints top right edge of the cell

Parameters

rect (QRectF) –

Cell rect of cell, for which the edge is painted

top

T | TR

left ———— right
C | R

bottom

class grid_renderer.EdgeBorders(left_width, right_width, top_width, bottom_width, left_color, right_color, top_color, bottom_color, left_x, right_x, top_y, bottom_y)[source]

Bases: object

Holds border data for an edge

bottom_color: PyQt5.QtGui.QColor
bottom_width: float
bottom_y: float
property colors: Tuple[PyQt5.QtGui.QColor, PyQt5.QtGui.QColor, PyQt5.QtGui.QColor, PyQt5.QtGui.QColor]

Tuple of border colors in order left, right, top, bottom

Return type

Tuple[QColor, QColor, QColor, QColor]

left_color: PyQt5.QtGui.QColor
left_width: float
left_x: float
right_color: PyQt5.QtGui.QColor
right_width: float
right_x: float
top_color: PyQt5.QtGui.QColor
top_width: float
top_y: float
property widths: Tuple[float, float, float, float]

Tuple of border widths in order left, right, top, bottom

Return type

Tuple[float, float, float, float]

class grid_renderer.GridCellNavigator(grid, key)[source]

Bases: object

Find neighbors of a cell

Parameters
  • grid (QTableView) – The main grid widget

  • key (Tuple[int, int, int]) – Key of cell fow which neighbors are identified

_merging_key(key)[source]

Merging cell if cell is merged else cell key

Parameters

key (Tuple[int, int, int]) – Key of cell that is checked for being merged

Return type

Tuple[int, int, int]

above_keys()[source]

Key list of neighboring cells above the key cell

Return type

List[Tuple[int, int, int]]

above_left_key()[source]

Key of neighboring cell above left of the key cell

Return type

Tuple[int, int, int]

above_right_key()[source]

Key of neighboring cell above right of the key cell

Return type

Tuple[int, int, int]

below_keys()[source]

Key list of neighboring cells below the key cell

Return type

List[Tuple[int, int, int]]

below_left_key()[source]

Key of neighboring cell below left of the key cell

Return type

Tuple[int, int, int]

below_right_key()[source]

Key of neighboring cell below right of the key cell

Return type

Tuple[int, int, int]

property border_color_bottom: PyQt5.QtGui.QColor

Color of bottom border line

Return type

QColor

property border_color_right: PyQt5.QtGui.QColor

Color of right border line

Return type

QColor

property borderwidth_bottom: float

Width of bottom border line

Return type

float

property borderwidth_right: float

Width of right border line

Return type

float

left_keys()[source]

Key list of neighboring cells left of the key cell

Return type

List[Tuple[int, int, int]]

property merge_area: Tuple[int, int, int, int]

Merge area of the key cell

Return type

Tuple[int, int, int, int]

right_keys()[source]

Key list of neighboring cells right of the key cell

Return type

List[Tuple[int, int, int]]

class grid_renderer.QColorCache(grid, *args, **kwargs)[source]

Bases: dict

QColor cache that returns default color for None

grid_renderer.painter_rotate(painter, rect, angle=0)[source]

Context manager rotating and restoring the painter

Parameters
  • painter (QPainter) – Painter, which is rotated

  • rect (QRectF) – Rect to be painted in

  • angle (int) – Rotataion angle must be in (0, 90, 180, 270)

Return type

QRectF

grid_renderer.painter_save(painter)[source]

Context manager saving and restoring painter state

Parameters

painter (QPainter) – Painter, for which the state is preserved

grid_renderer.painter_zoom(painter, zoom, rect)[source]

Context manager scaling and restoring the painter

(rect.x(), rect.y()) is invariant

Parameters
  • painter (QPainter) – Painter, for which the state is preserved

  • zoom (float) – Zoom factor

  • rect (QRectF) – Rect for setting zoom invariant point (rect.x(), rect.y())

Return type

QRectF