Class: QgsLayoutItemMapGrid¶
-
class
qgis.core.
QgsLayoutItemMapGrid
(name: str, map: QgsLayoutItemMap)¶ Bases:
QgsLayoutItemMapItem
Constructor for QgsLayoutItemMapGrid.
- Parameters
name (str) – friendly display name for grid
map (QgsLayoutItemMap) –
QgsLayoutItemMap
the grid is attached to
An individual grid which is drawn above the map content in a
QgsLayoutItemMap
.See also
Methods
- param visitor
Returns the direction for drawing frame annotations, on the specified
side
of the map.Returns the display mode for the grid annotations on a specified side of the map frame.
Returns whether annotations are shown for the grid.
Returns the expression used for drawing grid annotations.
Returns the font used for drawing grid annotations.
Returns the font color used for drawing grid annotations.
Returns the format for drawing grid annotations.
Returns the distance between the map frame and annotations.
Returns the position for the grid annotations on a specified
side
of the map frame.Returns the coordinate precision for grid annotations, which is the number of decimal places shown when drawing grid annotations.
Retrieves the blending mode used for drawing the grid.
Calculates the maximum distance the grid extends beyond the QgsLayoutItemMap’s item rect.
- rtype
QgsExpressionContext
Retrieves the length (in layout units) of the cross segments drawn for the grid.
Retrieves the CRS for the grid.
- param painter
Returns the type of grid divisions which are used for frames on a specified
side
of the map.Retrieves the first fill color for the grid frame.
Retrieves the second fill color for the grid frame.
Sets the grid frame Margin (in layout units).
Retrieves the color of the stroke drawn in the grid frame.
Retrieves the width of the stroke drawn in the grid frame.
Returns the flags which control which sides of the map item the grid frame is drawn on.
Returns the grid frame style.
Gets the grid frame width in layout units.
Returns the interval between grid lines in the x-direction.
Returns the interval between grid lines in the y-direction.
Returns the line symbol used for drawing grid lines.
Returns the marker symbol used for drawing grid points.
Calculates the maximum distance the grid extends beyond the QgsLayoutItemMap’s item rect (in layout units).
Returns the maximum width (in millimeters) for grid segments.
Returns the minimum width (in millimeters) for grid segments.
Returns the offset for grid lines in the x-direction.
Returns the offset for grid lines in the y-direction.
Sets object properties from a DOM element
- param itemElem
Sets the
direction
for drawing frame annotations for the specified mapside
.Sets what types of grid annotations should be drawn for a specified side of the map frame, or whether grid annotations should be disabled for the side.
Sets whether annotations should be shown for the grid.
Sets the
expression
used for drawing grid annotations.Sets the
font
used for drawing grid annotations.Sets the font
color
used for drawing grid annotations.Sets the
format
for drawing grid annotations.Sets the
distance
between the map frame and annotations.Sets the
position
for the grid annotations on a specifiedside
of the map frame.Sets the coordinate
precision
for grid annotations.Sets the blending
mode
used for drawing the grid.Sets the
length
(in layout units) of the cross segments drawn for the grid.Sets the
crs
for the grid.- param enabled
Sets what type of grid
divisions
should be used for frames on a specifiedside
of the map.Sets the first fill
color
used for the grid frame.Sets the second fill
color
used for the grid frame.Sets the grid frame margin (in layout units).
Sets the
color
of the stroke drawn in the grid frame.Sets the
width
of the stroke drawn in the grid frame.Sets whether the grid frame is drawn for a certain side of the map item.
Sets
flags
for grid frame sides.Sets the grid frame
style
.Sets the grid frame
width
(in layout units).Sets the
color
of grid lines.Sets the
width
of grid lines (in layout units).Sets the
interval
between grid lines in the x-direction.Sets the
interval
between grid lines in the y-direction.Sets the line
symbol
used for drawing grid lines.Sets the marker
symbol
used for drawing grid points.Sets the maximum
width
(in millimeters) for grid segments.Sets the minimum
width
(in millimeters) for grid segments.Sets the
offset
for grid lines in the x-direction.Sets the
offset
for grid lines in the y-direction.Sets the grid
style
, which controls how the grid is drawn over the map’s contents.Sets the
unit
to use for grid measurements such as the interval and offset for grid lines.Returns the grid’s style, which controls how the grid is drawn over the map’s contents.
Tests whether the grid frame should be drawn on a specified side of the map item.
Returns the units used for grid measurements such as the interval and offset for grid lines.
- rtype
bool
Stores object properties within an XML DOM element.
- param elem
Attributes
-
class
AnnotationCoordinate
¶ Bases:
int
-
class
AnnotationDirection
¶ Bases:
int
-
class
AnnotationFormat
¶ Bases:
int
-
class
AnnotationPosition
¶ Bases:
int
-
class
BorderSide
¶ Bases:
int
-
Bottom
= 2¶
-
BoundaryDirection
= 3¶
-
CM
= 2¶
-
Cross
= 1¶
-
CustomFormat
= 8¶
-
Decimal
= 0¶
-
DecimalWithSuffix
= 3¶
-
DegreeMinute
= 1¶
-
DegreeMinuteNoSuffix
= 4¶
-
DegreeMinutePadded
= 5¶
-
DegreeMinuteSecond
= 2¶
-
DegreeMinuteSecondNoSuffix
= 6¶
-
DegreeMinuteSecondPadded
= 7¶
-
class
DisplayMode
¶ Bases:
int
-
DynamicPageSizeBased
= 3¶
-
ExteriorTicks
= 3¶
-
FrameAnnotationsOnly
= 3¶
-
FrameBottom
= 8¶
-
FrameLeft
= 1¶
-
FrameRight
= 2¶
-
class
FrameSideFlag
¶ Bases:
int
-
class
FrameSideFlags
¶ Bases:
sip.wrapper
QgsLayoutItemMapGrid.FrameSideFlags(Union[QgsLayoutItemMapGrid.FrameSideFlags, QgsLayoutItemMapGrid.FrameSideFlag]) QgsLayoutItemMapGrid.FrameSideFlags(QgsLayoutItemMapGrid.FrameSideFlags)
-
class
FrameStyle
¶ Bases:
int
-
FrameTop
= 4¶
-
class
GridStyle
¶ Bases:
int
-
class
GridUnit
¶ Bases:
int
-
HideAll
= 3¶
-
Horizontal
= 0¶
-
InsideMapFrame
= 0¶
-
InteriorExteriorTicks
= 4¶
-
InteriorTicks
= 2¶
-
Latitude
= 1¶
-
LatitudeOnly
= 1¶
-
Left
= 0¶
-
LineBorder
= 5¶
-
LineBorderNautical
= 6¶
-
Longitude
= 0¶
-
LongitudeOnly
= 2¶
-
MM
= 1¶
-
MapUnit
= 0¶
-
Markers
= 2¶
-
NoFrame
= 0¶
-
OutsideMapFrame
= 1¶
-
Right
= 1¶
-
ShowAll
= 0¶
-
Solid
= 0¶
-
Top
= 3¶
-
Vertical
= 1¶
-
VerticalDescending
= 2¶
-
Zebra
= 1¶
-
ZebraNautical
= 7¶
-
accept
(self, visitor: QgsStyleEntityVisitorInterface) → bool¶ - Parameters
visitor (QgsStyleEntityVisitorInterface) –
- Return type
bool
-
annotationDirection
(self, border: QgsLayoutItemMapGrid.BorderSide) → QgsLayoutItemMapGrid.AnnotationDirection¶ Returns the direction for drawing frame annotations, on the specified
side
of the map.See also
- Parameters
border (QgsLayoutItemMapGrid.BorderSide) –
- Return type
-
annotationDisplay
(self, border: QgsLayoutItemMapGrid.BorderSide) → QgsLayoutItemMapGrid.DisplayMode¶ Returns the display mode for the grid annotations on a specified side of the map frame. This property also specifies whether annotations have been disabled from a side of the map frame.
- Parameters
border (QgsLayoutItemMapGrid.BorderSide) – side of map for annotations
- Return type
- Returns
display mode for grid annotations
See also
-
annotationEnabled
(self) → bool¶ Returns whether annotations are shown for the grid.
See also
- Return type
bool
-
annotationExpression
(self) → str¶ Returns the expression used for drawing grid annotations. This is only used when annotationFormat() is QgsLayoutItemMapGrid.CustomFormat.
See also
- Return type
str
-
annotationFont
(self) → QFont¶ Returns the font used for drawing grid annotations.
See also
- Return type
QFont
-
annotationFontColor
(self) → QColor¶ Returns the font color used for drawing grid annotations.
See also
- Return type
QColor
-
annotationFormat
(self) → QgsLayoutItemMapGrid.AnnotationFormat¶ Returns the format for drawing grid annotations.
See also
- Return type
-
annotationFrameDistance
(self) → float¶ Returns the distance between the map frame and annotations. Units are in layout units.
See also
- Return type
float
-
annotationPosition
(self, side: QgsLayoutItemMapGrid.BorderSide) → QgsLayoutItemMapGrid.AnnotationPosition¶ Returns the position for the grid annotations on a specified
side
of the map frame.See also
- Parameters
side (QgsLayoutItemMapGrid.BorderSide) –
- Return type
-
annotationPrecision
(self) → int¶ Returns the coordinate precision for grid annotations, which is the number of decimal places shown when drawing grid annotations.
See also
- Return type
int
-
blendMode
(self) → QPainter.CompositionMode¶ Retrieves the blending mode used for drawing the grid.
See also
- Return type
QPainter.CompositionMode
-
calculateMaxExtension
(self) → Tuple[float, float, float, float]¶ Calculates the maximum distance the grid extends beyond the QgsLayoutItemMap’s item rect. This method calculates the distance for each side of the map item separately.
See also
- Return type
Tuple[float, float, float, float]
-
childEvent
(self, QChildEvent)¶
-
connectNotify
(self, QMetaMethod)¶
-
createExpressionContext
(self) → QgsExpressionContext¶ - Return type
-
crossLength
(self) → float¶ Retrieves the length (in layout units) of the cross segments drawn for the grid. This is only used for grids with QgsLayoutItemMapGrid.Cross styles.
See also
- Return type
float
-
crs
(self) → QgsCoordinateReferenceSystem¶ Retrieves the CRS for the grid.
See also
- Return type
-
customEvent
(self, QEvent)¶
-
disconnectNotify
(self, QMetaMethod)¶
-
draw
(self, painter: QPainter)¶ - Parameters
painter (QPainter) –
-
frameDivisions
(self, side: QgsLayoutItemMapGrid.BorderSide) → QgsLayoutItemMapGrid.DisplayMode¶ Returns the type of grid divisions which are used for frames on a specified
side
of the map.See also
- Parameters
side (QgsLayoutItemMapGrid.BorderSide) –
- Return type
-
frameFillColor1
(self) → QColor¶ Retrieves the first fill color for the grid frame.
See also
See also
See also
- Return type
QColor
-
frameFillColor2
(self) → QColor¶ Retrieves the second fill color for the grid frame.
See also
See also
See also
- Return type
QColor
-
frameMargin
(self) → float¶ Sets the grid frame Margin (in layout units). This property controls distance between the map frame and the grid frame.
See also
New in version 3.6.
- Return type
float
-
framePenColor
(self) → QColor¶ Retrieves the color of the stroke drawn in the grid frame.
See also
See also
See also
See also
- Return type
QColor
-
framePenSize
(self) → float¶ Retrieves the width of the stroke drawn in the grid frame.
See also
See also
- Return type
float
-
frameSideFlags
(self) → QgsLayoutItemMapGrid.FrameSideFlags¶ Returns the flags which control which sides of the map item the grid frame is drawn on.
See also
See also
See also
- Return type
-
frameStyle
(self) → QgsLayoutItemMapGrid.FrameStyle¶ Returns the grid frame style.
See also
- Return type
-
frameWidth
(self) → float¶ Gets the grid frame width in layout units. This property controls how wide the grid frame is. The size of the line outlines drawn in the frame can be retrieved via the framePenSize method.
See also
- Return type
float
-
intervalX
(self) → float¶ Returns the interval between grid lines in the x-direction. The units are retrieved through the units() method.
See also
See also
- Return type
float
-
intervalY
(self) → float¶ Returns the interval between grid lines in the y-direction. The units are retrieved through the units() method.
See also
See also
- Return type
float
-
isSignalConnected
(self, QMetaMethod) → bool¶
-
lineSymbol
(self) → QgsLineSymbol¶ Returns the line symbol used for drawing grid lines. This is only used for grids with QgsLayoutItemMapGrid.Solid or QgsLayoutItemMapGrid.Cross styles.
See also
See also
See also
- Return type
-
markerSymbol
(self) → QgsMarkerSymbol¶ Returns the marker symbol used for drawing grid points. This is only used for grids with a QgsLayoutItemMapGrid.Markers style.
See also
See also
See also
- Return type
-
maxExtension
(self) → float¶ Calculates the maximum distance the grid extends beyond the QgsLayoutItemMap’s item rect (in layout units).
- Return type
float
-
maximumIntervalWidth
(self) → float¶ Returns the maximum width (in millimeters) for grid segments. This property is only effective if the units() is set to DynamicPageSizeBased.
See also
See also
See also
New in version 3.10.
- Return type
float
-
minimumIntervalWidth
(self) → float¶ Returns the minimum width (in millimeters) for grid segments. This property is only effective if the units() is set to DynamicPageSizeBased.
See also
See also
See also
New in version 3.10.
- Return type
float
-
offsetX
(self) → float¶ Returns the offset for grid lines in the x-direction. The units are retrieved through the units() method.
See also
See also
- Return type
float
-
offsetY
(self) → float¶ Returns the offset for grid lines in the y-direction. The units are retrieved through the units() method.
See also
See also
- Return type
float
-
readObjectPropertiesFromElement
(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool¶ Sets object properties from a DOM element
- Parameters
parentElement – is the parent DOM element for the object
document – DOM document
context – read write context
- Returns
True
if read was successful
See also
-
readXml
(self, itemElem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext) → bool¶ - Parameters
itemElem (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool
-
receivers
(self, PYQT_SIGNAL) → int¶
-
refresh
(self)¶
-
sender
(self) → QObject¶
-
senderSignalIndex
(self) → int¶
-
setAnnotationDirection
(self, direction: QgsLayoutItemMapGrid.AnnotationDirection, side: QgsLayoutItemMapGrid.BorderSide)¶ Sets the
direction
for drawing frame annotations for the specified mapside
.See also
setAnnotationDirection(self, direction: QgsLayoutItemMapGrid.AnnotationDirection) Sets the
direction
for drawing all frame annotations.See also
- Parameters
direction (QgsLayoutItemMapGrid.AnnotationDirection) –
side (QgsLayoutItemMapGrid.BorderSide) –
-
setAnnotationDisplay
(self, display: QgsLayoutItemMapGrid.DisplayMode, border: QgsLayoutItemMapGrid.BorderSide)¶ Sets what types of grid annotations should be drawn for a specified side of the map frame, or whether grid annotations should be disabled for the side.
- Parameters
display (QgsLayoutItemMapGrid.DisplayMode) – display mode for annotations
border (QgsLayoutItemMapGrid.BorderSide) – side of map for annotations
See also
-
setAnnotationEnabled
(self, enabled: bool)¶ Sets whether annotations should be shown for the grid.
See also
- Parameters
enabled (bool) –
-
setAnnotationExpression
(self, expression: str)¶ Sets the
expression
used for drawing grid annotations. This is only used when annotationFormat() is QgsLayoutItemMapGrid.CustomFormat.See also
- Parameters
expression (str) –
-
setAnnotationFont
(self, font: QFont)¶ Sets the
font
used for drawing grid annotations.See also
- Parameters
font (QFont) –
-
setAnnotationFontColor
(self, color: Union[QColor, Qt.GlobalColor])¶ Sets the font
color
used for drawing grid annotations.See also
- Parameters
color (Union[QColor) –
-
setAnnotationFormat
(self, format: QgsLayoutItemMapGrid.AnnotationFormat)¶ Sets the
format
for drawing grid annotations.See also
- Parameters
format (QgsLayoutItemMapGrid.AnnotationFormat) –
-
setAnnotationFrameDistance
(self, distance: float)¶ Sets the
distance
between the map frame and annotations. Units are layout units.See also
- Parameters
distance (float) –
-
setAnnotationPosition
(self, position: QgsLayoutItemMapGrid.AnnotationPosition, side: QgsLayoutItemMapGrid.BorderSide)¶ Sets the
position
for the grid annotations on a specifiedside
of the map frame.See also
- Parameters
position (QgsLayoutItemMapGrid.AnnotationPosition) –
side (QgsLayoutItemMapGrid.BorderSide) –
-
setAnnotationPrecision
(self, precision: int)¶ Sets the coordinate
precision
for grid annotations. Theprecision
indicates the number of decimal places to show when drawing grid annotations.See also
- Parameters
precision (int) –
-
setBlendMode
(self, mode: QPainter.CompositionMode)¶ Sets the blending
mode
used for drawing the grid.See also
- Parameters
mode (QPainter.CompositionMode) –
-
setCrossLength
(self, length: float)¶ Sets the
length
(in layout units) of the cross segments drawn for the grid. This is only used for grids with QgsLayoutItemMapGrid.Cross styles.See also
- Parameters
length (float) –
-
setCrs
(self, crs: QgsCoordinateReferenceSystem)¶ Sets the
crs
for the grid.See also
- Parameters
crs (QgsCoordinateReferenceSystem) –
-
setEnabled
(self, enabled: bool)¶ - Parameters
enabled (bool) –
-
setFrameDivisions
(self, divisions: QgsLayoutItemMapGrid.DisplayMode, side: QgsLayoutItemMapGrid.BorderSide)¶ Sets what type of grid
divisions
should be used for frames on a specifiedside
of the map.See also
- Parameters
divisions (QgsLayoutItemMapGrid.DisplayMode) –
side (QgsLayoutItemMapGrid.BorderSide) –
-
setFrameFillColor1
(self, color: Union[QColor, Qt.GlobalColor])¶ Sets the first fill
color
used for the grid frame.See also
See also
See also
- Parameters
color (Union[QColor) –
-
setFrameFillColor2
(self, color: Union[QColor, Qt.GlobalColor])¶ Sets the second fill
color
used for the grid frame.See also
See also
See also
- Parameters
color (Union[QColor) –
-
setFrameMargin
(self, margin: float)¶ Sets the grid frame margin (in layout units). This property controls distance between the map frame and the grid frame.
See also
New in version 3.6.
- Parameters
margin (float) –
-
setFramePenColor
(self, color: Union[QColor, Qt.GlobalColor])¶ Sets the
color
of the stroke drawn in the grid frame.See also
See also
See also
See also
- Parameters
color (Union[QColor) –
-
setFramePenSize
(self, width: float)¶ Sets the
width
of the stroke drawn in the grid frame.See also
See also
- Parameters
width (float) –
-
setFrameSideFlag
(self, flag: QgsLayoutItemMapGrid.FrameSideFlag, on: bool = True)¶ Sets whether the grid frame is drawn for a certain side of the map item.
- Parameters
flag (QgsLayoutItemMapGrid.FrameSideFlag) – flag for grid frame side
on (bool = True) – set to
True
to draw grid frame on that side of the map
See also
See also
See also
-
setFrameSideFlags
(self, flags: Union[QgsLayoutItemMapGrid.FrameSideFlags, QgsLayoutItemMapGrid.FrameSideFlag])¶ Sets
flags
for grid frame sides. Setting these flags controls which sides of the map item the grid frame is drawn on.See also
See also
See also
- Parameters
flags (Union[QgsLayoutItemMapGrid.FrameSideFlags) –
-
setFrameStyle
(self, style: QgsLayoutItemMapGrid.FrameStyle)¶ Sets the grid frame
style
.See also
- Parameters
style (QgsLayoutItemMapGrid.FrameStyle) –
-
setFrameWidth
(self, width: float)¶ Sets the grid frame
width
(in layout units). This property controls how wide the grid frame is. The size of the line outlines drawn in the frame is controlled through the setFramePenSize method.See also
- Parameters
width (float) –
-
setGridLineColor
(self, color: Union[QColor, Qt.GlobalColor])¶ Sets the
color
of grid lines. This is only used for grids with QgsLayoutItemMapGrid.Solid or QgsLayoutItemMapGrid.Cross styles. For more control over grid line appearance, use setLineSymbol instead.See also
See also
- Parameters
color (Union[QColor) –
-
setGridLineWidth
(self, width: float)¶ Sets the
width
of grid lines (in layout units). This is only used for grids with QgsLayoutItemMapGrid.Solid or QgsLayoutItemMapGrid.Cross styles. For more control over grid line appearance, use setLineSymbol instead.See also
See also
- Parameters
width (float) –
-
setIntervalX
(self, interval: float)¶ Sets the
interval
between grid lines in the x-direction. The units are controlled through the setUnits methodSee also
See also
- Parameters
interval (float) –
-
setIntervalY
(self, interval: float)¶ Sets the
interval
between grid lines in the y-direction. The units are controlled through the setUnits methodSee also
See also
- Parameters
interval (float) –
-
setLineSymbol
(self, symbol: QgsLineSymbol)¶ Sets the line
symbol
used for drawing grid lines. This is only used for grids with QgsLayoutItemMapGrid.Solid or QgsLayoutItemMapGrid.Cross styles. Ownership ofsymbol
is transferred to the grid.See also
See also
See also
- Parameters
symbol (QgsLineSymbol) –
-
setMarkerSymbol
(self, symbol: QgsMarkerSymbol)¶ Sets the marker
symbol
used for drawing grid points. This is only used for grids with a QgsLayoutItemMapGrid.Markers style. Ownership ofsymbol
is transferred to the grid.See also
See also
See also
- Parameters
symbol (QgsMarkerSymbol) –
-
setMaximumIntervalWidth
(self, width: float)¶ Sets the maximum
width
(in millimeters) for grid segments. This property is only effective if the units() is set to DynamicPageSizeBased.See also
See also
See also
New in version 3.10.
- Parameters
width (float) –
-
setMinimumIntervalWidth
(self, width: float)¶ Sets the minimum
width
(in millimeters) for grid segments. This property is only effective if the units() is set to DynamicPageSizeBased.See also
See also
See also
New in version 3.10.
- Parameters
width (float) –
-
setOffsetX
(self, offset: float)¶ Sets the
offset
for grid lines in the x-direction. The units are controlled through the setUnits method.See also
See also
- Parameters
offset (float) –
-
setOffsetY
(self, offset: float)¶ Sets the
offset
for grid lines in the y-direction. The units are controlled through the setUnits method.See also
See also
- Parameters
offset (float) –
-
setStyle
(self, style: QgsLayoutItemMapGrid.GridStyle)¶ Sets the grid
style
, which controls how the grid is drawn over the map’s contents.See also
- Parameters
style (QgsLayoutItemMapGrid.GridStyle) –
-
setUnits
(self, unit: QgsLayoutItemMapGrid.GridUnit)¶ Sets the
unit
to use for grid measurements such as the interval and offset for grid lines.See also
- Parameters
unit (QgsLayoutItemMapGrid.GridUnit) –
-
style
(self) → QgsLayoutItemMapGrid.GridStyle¶ Returns the grid’s style, which controls how the grid is drawn over the map’s contents.
See also
- Return type
-
testFrameSideFlag
(self, flag: QgsLayoutItemMapGrid.FrameSideFlag) → bool¶ Tests whether the grid frame should be drawn on a specified side of the map item.
- Parameters
flag (QgsLayoutItemMapGrid.FrameSideFlag) – flag for grid frame side
- Return type
bool
- Returns
True
if grid frame should be drawn for that side of the map
See also
See also
See also
-
timerEvent
(self, QTimerEvent)¶
-
units
(self) → QgsLayoutItemMapGrid.GridUnit¶ Returns the units used for grid measurements such as the interval and offset for grid lines.
See also
- Return type
-
usesAdvancedEffects
(self) → bool¶ - Return type
bool
-
writeObjectPropertiesToElement
(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool¶ Stores object properties within an XML DOM element.
- Parameters
parentElement – is the parent DOM element to store the object’s properties in
document – DOM document
context – read write context
- Returns
True
if write was successful
See also
-
writeXml
(self, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext) → bool¶ - Parameters
elem (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool