Class: QgsHighlight

class qgis.gui.QgsHighlight

Bases: QgsMapCanvasItem

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()

QgsHighlight(mapCanvas: Optional[QgsMapCanvas], geom: QgsGeometry, layer: Optional[QgsMapLayer]) Constructor for QgsHighlight

Parameters:
  • mapCanvas – associated map canvas

  • geom – initial geometry of highlight

  • layer – associated map layer

QgsHighlight(mapCanvas: Optional[QgsMapCanvas], feature: QgsFeature, layer: Optional[QgsVectorLayer]) Constructor for highlighting True feature shape using feature attributes and renderer.

Parameters:
applyDefaultStyle(self)

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

Added in version 3.30.

buffer(self) float

Returns the buffer

Added in version 3.4.

Return type:

float

color(self) QColor

Returns the line/stroke color

Added in version 3.4.

Return type:

QColor

contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent | None)
dragEnterEvent(self, event: QGraphicsSceneDragDropEvent | None)
dragLeaveEvent(self, event: QGraphicsSceneDragDropEvent | None)
dragMoveEvent(self, event: QGraphicsSceneDragDropEvent | None)
dropEvent(self, event: QGraphicsSceneDragDropEvent | None)
fillColor(self) QColor

Returns the fill color

Added in version 3.4.

Return type:

QColor

focusInEvent(self, event: QFocusEvent | None)
focusOutEvent(self, event: QFocusEvent | None)
hoverEnterEvent(self, event: QGraphicsSceneHoverEvent | None)
hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent | None)
hoverMoveEvent(self, event: QGraphicsSceneHoverEvent | None)
inputMethodEvent(self, event: QInputMethodEvent | None)
inputMethodQuery(self, query: Qt.InputMethodQuery) Any
itemChange(self, change: QGraphicsItem.GraphicsItemChange, value: Any) Any
keyPressEvent(self, event: QKeyEvent | None)
keyReleaseEvent(self, event: QKeyEvent | None)
layer(self) QgsMapLayer | None

Returns the layer for which this highlight has been created.

Return type:

Optional[QgsMapLayer]

mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent | None)
mouseMoveEvent(self, event: QGraphicsSceneMouseEvent | None)
mousePressEvent(self, event: QGraphicsSceneMouseEvent | None)
mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent | None)
paint(self, p: QPainter | None)
Parameters:

p (Optional[QPainter])

prepareGeometryChange(self)
sceneEvent(self, event: QEvent | None) bool
sceneEventFilter(self, watched: QGraphicsItem | None, event: QEvent | None) bool
setBuffer(self, buffer: float)

Set line / stroke buffer in millimeters.

Parameters:

buffer (float)

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

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)

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

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

Parameters:

fillColor (Union[QColor)

setMinWidth(self, width: float)

Set minimum line / stroke width in millimeters.

Parameters:

width (float)

setRenderContextVariables(self, p: QPainter | None, context: QgsRenderContext) bool

Sets render context parameters

Parameters:
  • p – painter for rendering

  • context – out: configured context

Returns:

True in case of success

setWidth(self, width: int)

Set stroke width.

Note

Ignored in feature mode.

Parameters:

width (int)

updateCanvas(self)

schedules map canvas for repaint

updateMicroFocus(self)
updatePosition(self)
updateRect(self)

recalculates needed rectangle

wheelEvent(self, event: QGraphicsSceneWheelEvent | None)
width(self) int

Returns the stroke width

Added in version 3.4.

Return type:

int