Wednesday 24 May 2017

qgis - How to change the color of a selected feature with pyQGIS?


is it possible to change the color of a selected feature in qgis 1.8? To highlight a feature I use:


vlayer.setSelectedFeatures(selectedList)
box = vlayer.boundingBoxOfSelected()
qgis.utils.iface.mapCanvas().setExtent(box)
qgis.utils.iface.mapCanvas().refresh()


But the selected featue is colored yellow. Is it possible to define for example a red color for this feature?



Answer



For reference, if you use QGIS >= v.2.4, you can set the selection color from the QGIS Python console in this way:


from PyQt4.QtGui import QColor
iface.mapCanvas().setSelectionColor( QColor("red") )

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...