Class: QgsHighlight

A class for highlight features on the map.

The QgsHighlight class provides a transparent overlay canvas item for highlighting features or geometries on a map canvas.

color = QColor(Qt.red)
highlight = QgsHighlight(mapCanvas, feature, layer)
highlight.setColor(color)
color.setAlpha(50)
highlight.setFillColor(color)
highlight.show()

Class Hierarchy

Inheritance diagram of qgis.gui.QgsHighlight

Base classes

QgsMapCanvasItem

An abstract class for items that can be placed on the map canvas.

QGraphicsItem

Methods

applyDefaultStyle

Applies the default style from the user settings to the highlight.

buffer

Returns the line/stroke buffer size (in millimeters)

color

Returns the line/stroke color

fillColor

Returns the fill color

layer

Returns the layer for which this highlight has been created.

setBuffer

Sets the line/stroke buffer size (in millimeters).

setColor

Set line/stroke to color, polygon fill to color with alpha = 63.

setFillColor

Fill color for the highlight.

setMinWidth

Sets the minimum line/stroke width (in millimeters).

setWidth

Set stroke width.

updateRect

recalculates needed rectangle

width

Returns the stroke width

class qgis.gui.QgsHighlight[source]

Bases: QgsMapCanvasItem

__init__(mapCanvas: QgsMapCanvas | None, geom: QgsGeometry, layer: QgsMapLayer | None)

Constructor for QgsHighlight

Parameters:
  • mapCanvas (Optional[QgsMapCanvas]) – associated map canvas

  • geom (QgsGeometry) – initial geometry of highlight

  • layer (Optional[QgsMapLayer]) – associated map layer

__init__(mapCanvas: QgsMapCanvas | None, feature: QgsFeature, layer: QgsVectorLayer | None)

Constructor for highlighting True feature shape using feature attributes and renderer.

Parameters:
applyDefaultStyle(self)[source]

Applies the default style from the user settings to the highlight.

Added in version 3.30.

buffer(self) float[source]

Returns the line/stroke buffer size (in millimeters)

See also

setBuffer()

Added in version 3.4.

Return type:

float

color(self) QColor[source]

Returns the line/stroke color

Added in version 3.4.

Return type:

QColor

fillColor(self) QColor[source]

Returns the fill color

Added in version 3.4.

Return type:

QColor

layer(self) QgsMapLayer | None[source]

Returns the layer for which this highlight has been created.

Return type:

Optional[QgsMapLayer]

setBuffer(self, buffer: float)[source]

Sets the line/stroke buffer size (in millimeters).

See also

buffer()

Parameters:

buffer (float)

setColor(self, color: QColor | Qt.GlobalColor)[source]

Set line/stroke to color, polygon fill to color with alpha = 63. This is legacy function, use setFillColor() after setColor() if different fill color is required.

Parameters:

color (Union[QColor, Qt.GlobalColor])

setFillColor(self, fillColor: QColor | Qt.GlobalColor)[source]

Fill color for the highlight. Will be used for polygons and points.

Parameters:

fillColor (Union[QColor, Qt.GlobalColor])

setMinWidth(self, width: float)[source]

Sets the minimum line/stroke width (in millimeters).

Parameters:

width (float)

setWidth(self, width: int)[source]

Set stroke width.

Note

Ignored in feature mode.

Parameters:

width (int)

updateRect(self)[source]

recalculates needed rectangle

width(self) int[source]

Returns the stroke width

Added in version 3.4.

Return type:

int