[Qgis-user] remove highlights from map canvas
Reginald
Reginald.Carlier at ingelmunster.be
Wed Aug 19 23:48:12 PDT 2020
Hi,
I figured out how to get it working with QgsRubberBand. I don't know what is
exact the difference between QgsHighlight and QgsRubberBand but I wanted to
share this with anyone needing this functionality:
___________________________
--------------------------------------
from qgis.gui import QgsRubberBand
from PyQt5.QtGui import QColor
from PyQt5.QtCore import QTimer
h_dict = {}
layer = iface.activeLayer()
timer = QTimer()
# function that does the work of highlighting selected features
def highlight_features():
# create highlight geometries for selected objects
for i in layer.selectedFeatures():
fid = i.id()
h_dict[fid] = QgsRubberBand(iface.mapCanvas(),
QgsWkbTypes.PolygonGeometry)
# set highlight symbol properties
h_dict[fid].setColor(QColor(255,0,0,255))
h_dict[fid].setWidth(3)
h_dict[fid].setFillColor(QColor(255,255,255,0))
h_dict[fid].addGeometry(i.geometry(), None)
timer.start(30000)
def dim_feature():
if bool(h_dict):
for feat in h_dict:
iface.mapCanvas().scene().removeItem(h_dict[feat])
timer.timeout.connect(dim_feature)
# connect the function to the layer signal
layer.selectionChanged.connect(highlight_features)
----------------------------------------------------------
Regards,
--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
More information about the Qgis-user
mailing list