It is possible to label QgsRubberBand
or QgsVertexMarker
with a text annotation (QgsTextAnnotationItem
).
See this MWE:
...
r_polyline = QgsRubberBand(iface.mapCanvas(), False)
r_polyline.setToGeometry(QgsGeometry.fromPolyline(points), None)
r_polyline.setWidth(2)
r_polyline.setColor(QColor(0,255,0,255))
seg = QgsFeature()
seg.setGeometry(QgsGeometry.fromPolyline(points))
length = seg.geometry().length()
self.distance_list.append(length)
symbol = QgsMarkerSymbolV2()
symbol.setSize(0)
lbltext = QTextDocument(str(round(length,2)) + ' m')
label = QgsTextAnnotationItem(iface.mapCanvas())
label.setMapPosition(seg.geometry().interpolate(length/2.0).asPoint())
label.setDocument(lbltext)
label.setFrameSize(QSizeF(lbltext.size().width(),lbltext.size().height()))
label.setFrameBorderWidth(0)
label.setFrameColor(QColor("#ffffff"))
label.setFrameBackgroundColor(QColor("#ffffff"))
label.setMarkerSymbol(symbol)
...
In the moment it looks like this:
Is it possible to label a rubber band (or edit the text annotations) like in this picture?