Class: QgsLayoutGuideCollection

Stores and manages the snap guides used by a layout.

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutGuideCollection

Base classes

QAbstractTableModel

QAbstractItemModel

QObject

QgsLayoutSerializableObject

An interface for layout objects which can be stored and read from DOM elements.

QgsLayoutUndoObjectInterface

Interface for layout objects which support undo/redo commands.

Enums

CustomRole

Custom model roles.

Roles

alias of CustomRole

Abstract Methods

readXml

Sets the collection's state from a DOM element.

writeXml

Stores the collection's state in a DOM element.

Methods

addGuide

Adds a guide to the collection.

applyGuidesToAllOtherPages

Resets all other pages' guides to match the guides from the specified sourcePage.

clear

Removes all guides from the collection.

guides

Returns a list of all guides contained in the collection.

guidesOnPage

Returns the list of guides contained on a matching page.

removeGuide

Removes the specified guide, and deletes it.

setGuideLayoutPosition

Sets the absolute position (in layout coordinates) for guide within the layout.

setVisible

Sets whether the guide lines should be visible.

update

Updates the position (and visibility) of all guide line items.

visible

Returns True if the guide lines should be drawn.

class qgis.core.QgsLayoutGuideCollection[source]

Bases: QAbstractTableModel, QgsLayoutSerializableObject

__init__(layout: QgsLayout | None, pageCollection: QgsLayoutPageCollection | None)

Constructor for QgsLayoutGuideCollection belonging to the specified layout, and linked to the specified pageCollection.

Parameters:
class CustomRole(*values)

Bases: IntEnum

Custom model roles.

Note

Prior to QGIS 3.36 this was available as QgsLayoutGuideCollection.Roles

Added in version 3.36.

  • Orientation: Guide orientation role

    Available as QgsLayoutGuideCollection.OrientationRole in older QGIS releases.

  • Position: Guide position role

    Available as QgsLayoutGuideCollection.PositionRole in older QGIS releases.

  • Units: Guide position units role

    Available as QgsLayoutGuideCollection.UnitsRole in older QGIS releases.

  • Page: Guide page role

    Available as QgsLayoutGuideCollection.PageRole in older QGIS releases.

  • LayoutPosition: Guide position in layout coordinates

    Available as QgsLayoutGuideCollection.LayoutPositionRole in older QGIS releases.

Roles

alias of CustomRole

addGuide(self, guide: QgsLayoutGuide | None)[source]

Adds a guide to the collection. Ownership of the guide is transferred to the collection, and the guide will automatically have the correct layout set.

Parameters:

guide (Optional[QgsLayoutGuide])

applyGuidesToAllOtherPages(self, sourcePage: int)[source]

Resets all other pages’ guides to match the guides from the specified sourcePage.

Parameters:

sourcePage (int)

clear(self)[source]

Removes all guides from the collection.

See also

removeGuide()

guides(self) List[QgsLayoutGuide]

Returns a list of all guides contained in the collection.

Return type:

List[QgsLayoutGuide]

guides(self, orientation: Qt.Orientation, page: int = -1) List[QgsLayoutGuide]

Returns the list of guides contained in the collection with the specified orientation and on a matching page. If page is -1, guides from all pages will be returned.

See also

guidesOnPage()

Parameters:
  • orientation (Qt.Orientation)

  • page (int = -1)

Return type:

List[QgsLayoutGuide]

guidesOnPage(self, page: int) List[QgsLayoutGuide]

Returns the list of guides contained on a matching page.

See also

guides()

Parameters:

page (int)

Return type:

List[QgsLayoutGuide]

abstract readXml(self, collectionElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool[source]

Sets the collection’s state from a DOM element. collectionElement is the DOM node corresponding to the collection.

See also

writeXml()

Parameters:
Return type:

bool

removeGuide(self, guide: QgsLayoutGuide | None)[source]

Removes the specified guide, and deletes it.

See also

clear()

Parameters:

guide (Optional[QgsLayoutGuide])

setGuideLayoutPosition(self, guide: QgsLayoutGuide | None, position: float)[source]

Sets the absolute position (in layout coordinates) for guide within the layout.

Parameters:
setVisible(self, visible: bool)[source]

Sets whether the guide lines should be visible.

See also

visible()

Parameters:

visible (bool)

update(self)[source]

Updates the position (and visibility) of all guide line items.

visible(self) bool[source]

Returns True if the guide lines should be drawn.

See also

setVisible()

Return type:

bool

abstract writeXml(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool[source]

Stores the collection’s state in a DOM element. The parentElement should refer to the parent layout’s DOM element.

See also

readXml()

Parameters:
Return type:

bool