Subgroup: other

Class: QgsRubberBand

class qgis.gui.QgsRubberBand

Bases: qgis._gui.QgsMapCanvasItem

A class for drawing transient features (e.g. digitizing lines) on the map.

The QgsRubberBand class provides a transparent overlay widget for tracking the mouse while drawing polylines or polygons.

Methods

acceptDrops
acceptHoverEvents
acceptTouchEvents
acceptedMouseButtons
addGeometry Adds the geometry of an existing feature to a rubberband This is useful for multi feature highlighting.
addPoint Adds a vertex to the rubberband and update canvas.
advance
asGeometry Returns the rubberband as a Geometry
boundingRect
boundingRegion
boundingRegionGranularity
cacheMode
childItems
childrenBoundingRect
clearFocus
clipPath
closePoints Ensures that a polygon geometry is closed and that the last vertex equals the first vertex.
collidesWithItem
collidesWithPath
collidingItems
commonAncestorItem
contains
contextMenuEvent
cursor
data
deviceTransform
dragEnterEvent
dragLeaveEvent
dragMoveEvent
drawShape Draws shape of the rubber band.
dropEvent
effectiveOpacity
ensureVisible ensureVisible(self, float, float, float, float, xMargin: int = 50, yMargin: int = 50)
fillColor Returns the current fill color.
filtersChildEvents
flags
focusInEvent
focusItem
focusOutEvent
focusProxy
getPoint Returns a vertex
grabKeyboard
grabMouse
graphicsEffect
group
hasCursor
hasFocus
hide
hoverEnterEvent
hoverLeaveEvent
hoverMoveEvent
icon Returns the current icon type to highlight point geometries.
iconSize Returns the current icon size of the point icons.
inputMethodEvent
inputMethodHints
inputMethodQuery
installSceneEventFilter
isActive
isAncestorOf
isBlockedByModalPanel
isClipped
isEnabled
isObscured isObscured(self, float, float, float, float) -> bool
isObscuredBy
isPanel
isSelected
isUnderMouse
isVisible
isVisibleTo
isWidget
isWindow
itemChange
itemTransform
keyPressEvent
keyReleaseEvent
mapFromItem mapFromItem(self, QGraphicsItem, QRectF) -> QPolygonF
mapFromParent mapFromParent(self, QRectF) -> QPolygonF
mapFromScene mapFromScene(self, QRectF) -> QPolygonF
mapRectFromItem mapRectFromItem(self, QGraphicsItem, float, float, float, float) -> QRectF
mapRectFromParent mapRectFromParent(self, float, float, float, float) -> QRectF
mapRectFromScene mapRectFromScene(self, float, float, float, float) -> QRectF
mapRectToItem mapRectToItem(self, QGraphicsItem, float, float, float, float) -> QRectF
mapRectToParent mapRectToParent(self, float, float, float, float) -> QRectF
mapRectToScene mapRectToScene(self, float, float, float, float) -> QRectF
mapToItem mapToItem(self, QGraphicsItem, QRectF) -> QPolygonF
mapToParent mapToParent(self, QRectF) -> QPolygonF
mapToScene mapToScene(self, QRectF) -> QPolygonF
mouseDoubleClickEvent
mouseMoveEvent
mousePressEvent
mouseReleaseEvent
moveBy
movePoint Moves the rubber band point specified by index.
numberOfVertices Returns count of vertices in all lists of mPoint
opacity
opaqueArea
paint Paints the rubber band in response to an update event.
panel
panelModality
parentItem
parentObject
parentWidget
partSize Returns number of vertices in feature part
pos
prepareGeometryChange
rect returns canvas item rectangle in map units
removeLastPoint Removes the last point.
removePoint Removes a vertex from the rubberband and (optionally) updates canvas.
removeSceneEventFilter
reset Clears all the geometries in this rubberband.
resetTransform
rotation
scale
scene
sceneBoundingRect
sceneEvent
sceneEventFilter
scenePos
sceneTransform
scroll
secondaryStrokeColor Returns the current secondary stroke color.
setAcceptDrops
setAcceptHoverEvents
setAcceptTouchEvents
setAcceptedMouseButtons
setActive
setBoundingRegionGranularity
setBrushStyle Sets the style of the brush
setCacheMode
setColor Sets the color for the rubberband
setCursor
setData
setEnabled
setFillColor Sets the fill color for the rubberband
setFiltersChildEvents
setFlag
setFlags
setFocus
setFocusProxy
setGraphicsEffect
setGroup
setIcon Sets the icon type to highlight point geometries.
setIconSize Sets the size of the point icons
setInputMethodHints
setLineStyle Sets the style of the line
setOpacity
setPanelModality
setParentItem
setPos setPos(self, float, float)
setRect sets canvas item rectangle in map units
setRenderContextVariables
setRotation
setScale
setSecondaryStrokeColor Sets a secondary stroke color for the rubberband which will be drawn under the main stroke color.
setSelected
setStrokeColor Sets the stroke color for the rubberband
setToCanvasRectangle Sets this rubber band to a map canvas rectangle
setToGeometry Sets this rubber band to the geometry of an existing feature.
setToolTip
setTransform
setTransformOriginPoint setTransformOriginPoint(self, float, float)
setTransformations
setTranslationOffset Adds translation to original coordinates (all in map coordinates)
setVisible
setWidth Sets the width of the line.
setX
setY
setZValue
shape
show
size Returns number of geometries
stackBefore
strokeColor Returns the current stroke color.
toCanvasCoordinates transformation from map coordinates to screen coordinates
toGraphicsObject
toMapCoordinates transformation from screen coordinates to map coordinates
toolTip
topLevelItem
topLevelWidget
transform
transformOriginPoint
transformations
type
ungrabKeyboard
ungrabMouse
unsetCursor
update update(self, float, float, float, float)
updateCanvas
updateMicroFocus
updatePosition
updateRect Recalculates needed rectangle
wheelEvent
width Returns the current width of the line or stroke width for polygon.
window
x
y
zValue

Attributes

DeviceCoordinateCache
ICON_BOX
ICON_CIRCLE
ICON_CROSS
ICON_DIAMOND
ICON_FULL_BOX
ICON_FULL_DIAMOND
ICON_NONE
ICON_X
ItemAcceptsInputMethod
ItemChildAddedChange
ItemChildRemovedChange
ItemClipsChildrenToShape
ItemClipsToShape
ItemContainsChildrenInShape
ItemCoordinateCache
ItemCursorChange
ItemCursorHasChanged
ItemDoesntPropagateOpacityToChildren
ItemEnabledChange
ItemEnabledHasChanged
ItemFlagsChange
ItemFlagsHaveChanged
ItemHasNoContents
ItemIgnoresParentOpacity
ItemIgnoresTransformations
ItemIsFocusable
ItemIsMovable
ItemIsPanel
ItemIsSelectable
ItemMatrixChange
ItemNegativeZStacksBehindParent
ItemOpacityChange
ItemOpacityHasChanged
ItemParentChange
ItemParentHasChanged
ItemPositionChange
ItemPositionHasChanged
ItemRotationChange
ItemRotationHasChanged
ItemScaleChange
ItemScaleHasChanged
ItemSceneChange
ItemSceneHasChanged
ItemScenePositionHasChanged
ItemSelectedChange
ItemSelectedHasChanged
ItemSendsGeometryChanges
ItemSendsScenePositionChanges
ItemStacksBehindParent
ItemToolTipChange
ItemToolTipHasChanged
ItemTransformChange
ItemTransformHasChanged
ItemTransformOriginPointChange
ItemTransformOriginPointHasChanged
ItemUsesExtendedStyleOption
ItemVisibleChange
ItemVisibleHasChanged
ItemZValueChange
ItemZValueHasChanged
NoCache
NonModal
PanelModal
SceneModal
Type
UserType
ICON_BOX = 3
ICON_CIRCLE = 4
ICON_CROSS = 1
ICON_DIAMOND = 6
ICON_FULL_BOX = 5
ICON_FULL_DIAMOND = 7
ICON_NONE = 0
ICON_X = 2
class IconType

Bases: int

addGeometry(self, geometry: QgsGeometry, layer: QgsVectorLayer)

Adds the geometry of an existing feature to a rubberband This is useful for multi feature highlighting. As of 2.0, this method does not change the GeometryType any more. You need to set the GeometryType of the rubberband explicitly by calling reset() or setToGeometry() with appropriate arguments. setToGeometry() is also to be preferred for backwards-compatibility.

Parameters:
  • geometry – the geometry object. Will be treated as a collection of vertices.
  • layer – the layer containing the feature, used for coord transformation to map

crs. In case of 0 pointer, the coordinates are not going to be transformed.

addGeometry(self, geometry: QgsGeometry, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) Adds a geometry to the rubberband.

If crs is specified, the geometry will be automatically reprojected from crs to the canvas CRS.

New in version 3.0.

addPoint(self, p: QgsPointXY, doUpdate: bool = True, geometryIndex: int = 0)

Adds a vertex to the rubberband and update canvas. The rendering of the vertex depends on the current GeometryType and icon. If adding more points consider using update=false for better performance

Parameters:
  • p – The vertex/point to add
  • doUpdate – Should the map canvas be updated immediately?
  • geometryIndex – The index of the feature part (in case of multipart geometries)
asGeometry(self) → QgsGeometry

Returns the rubberband as a Geometry

Returns:A geometry object which reflects the current state of the rubberband.
closePoints(self, doUpdate: bool = True, geometryIndex: int = 0)

Ensures that a polygon geometry is closed and that the last vertex equals the first vertex.

Parameters:
  • doUpdate – set to true to update the map canvas immediately
  • geometryIndex – index of the feature part (in case of multipart geometries)

New in version 2.16.

contextMenuEvent()
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
drawShape(self, p: QPainter, pts: Iterable[Union[QPointF, QPoint]])

Draws shape of the rubber band.

Parameters:
  • p – The QPainter object
  • pts – A list of points used to draw the shape
dropEvent()
fillColor(self) → QColor

Returns the current fill color.

focusInEvent()
focusOutEvent()
getPoint(self, i: int, j: int = 0) → QgsPointXY

Returns a vertex

Parameters:
  • i – The geometry index
  • j – The vertex index within geometry i
hoverEnterEvent()
hoverLeaveEvent()
hoverMoveEvent()
icon(self) → QgsRubberBand.IconType

Returns the current icon type to highlight point geometries.

iconSize(self) → int

Returns the current icon size of the point icons.

inputMethodEvent()
inputMethodQuery()
itemChange()
keyPressEvent()
keyReleaseEvent()
mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
movePoint(self, p: QgsPointXY, geometryIndex: int = 0)

Moves the rubber band point specified by index. Note that if the rubber band is not used to track the last mouse position, the first point of the rubber band has two vertices

movePoint(self, index: int, p: QgsPointXY, geometryIndex: int = 0) Moves the rubber band point specified by index. Note that if the rubber band is not used to track the last mouse position, the first point of the rubber band has two vertices

numberOfVertices(self) → int

Returns count of vertices in all lists of mPoint

Returns:The total number of vertices
paint(self, p: QPainter)

Paints the rubber band in response to an update event.

Parameters:p – The QPainter object
partSize(self, geometryIndex: int) → int

Returns number of vertices in feature part

Parameters:geometryIndex – The index of the feature part (in case of multipart geometries)
Returns:number of vertices
prepareGeometryChange()
removeLastPoint(self, geometryIndex: int = 0, doUpdate: bool = True)

Removes the last point. Most useful in connection with undo operations

removePoint(self, index: int = 0, doUpdate: bool = True, geometryIndex: int = 0)

Removes a vertex from the rubberband and (optionally) updates canvas.

Parameters:
  • index – The index of the vertex/point to remove, negative indexes start at end
  • doUpdate – Should the map canvas be updated immediately?
  • geometryIndex – The index of the feature part (in case of multipart geometries)
reset(self, geometryType: QgsWkbTypes.GeometryType = QgsWkbTypes.LineGeometry)

Clears all the geometries in this rubberband. Sets the representation type according to geometryType.

Parameters:geometryType – Defines how the data should be drawn onto the screen. (Use Qgis.Line, Qgis.Polygon or Qgis.Point)
sceneEvent()
sceneEventFilter()
secondaryStrokeColor(self) → QColor

Returns the current secondary stroke color.

setBrushStyle(self, brushStyle: Qt.BrushStyle)

Sets the style of the brush

setColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets the color for the rubberband

Parameters:color – The color used to render this rubberband
setFillColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets the fill color for the rubberband

Parameters:color – The color used to render this rubberband

New in version 2.6.

setIcon(self, icon: QgsRubberBand.IconType)

Sets the icon type to highlight point geometries.

Parameters:icon – The icon to visualize point geometries
setIconSize(self, iconSize: int)

Sets the size of the point icons

setLineStyle(self, penStyle: Qt.PenStyle)

Sets the style of the line

setRenderContextVariables()
setSecondaryStrokeColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets a secondary stroke color for the rubberband which will be drawn under the main stroke color. Set to an invalid color to avoid drawing the secondary stroke.

Parameters:color – The color used to render a secondary stroke color to this rubberband

New in version 3.0.

setStrokeColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets the stroke color for the rubberband

Parameters:color – The color used to render this rubberband

New in version 2.6.

setToCanvasRectangle(self, rect: QRect)

Sets this rubber band to a map canvas rectangle

Parameters:rect – rectangle in canvas coordinates
setToGeometry(self, geom: QgsGeometry, layer: QgsVectorLayer)

Sets this rubber band to the geometry of an existing feature. This is useful for feature highlighting. In contrast to addGeometry(), this method does also change the geometry type of the rubberband.

Parameters:
  • geom – the geometry object
  • layer – the layer containing the feature, used for coord transformation to map

crs. In case of 0 pointer, the coordinates are not going to be transformed.

setTranslationOffset(self, dx: float, dy: float)

Adds translation to original coordinates (all in map coordinates)

Parameters:
  • dx – x translation
  • dy – y translation
setWidth(self, width: int)

Sets the width of the line. Stroke width for polygon.

Parameters:width – The width for any lines painted for this rubberband
size(self) → int

Returns number of geometries

Returns:number of geometries
strokeColor(self) → QColor

Returns the current stroke color.

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

Recalculates needed rectangle

wheelEvent()
width(self) → int

Returns the current width of the line or stroke width for polygon.