[QGIS-Developer] How to fix the color ramp item list for the UI
René-Luc Dhont
rldhont at gmail.com
Tue Nov 3 02:04:27 PST 2020
Hi devs,
I have an issue with the QGIS Raster Color Ramp UI, I can't get the
color ramp item list set with PyQGIS.
I have a PyQGIS Script to set the Raster Color Ramp like it is defined
in the pyQGIS cookbook. It works find for rendering and legend, but if I
open the Raster layer properties and look at the Style tab, the color
ramp list item is not exactly the same as the one I defined in my
script. Values and labels are saved, but the color is lost.
How to fixed the color ramp item list ?
The pyQGIS cookbook code [0] works for rendering but the UI loose the list.
If you try this code, you ill not get 2 items in the UI
```
fcn = QgsColorRampShader()
fcn.setColorRampType(QgsColorRampShader.Interpolated)
lst = [ QgsColorRampShader.ColorRampItem(0, QColor(0,255,0)),
QgsColorRampShader.ColorRampItem(255, QColor(255,255,0)) ]
fcn.setColorRampItemList(lst)
shader = QgsRasterShader()
shader.setRasterShaderFunction(fcn)
renderer = QgsSingleBandPseudoColorRenderer(rlayer.dataProvider(), 1,
shader)
rlayer.setRenderer(renderer)
rlayer.triggerRepaint()
```
Regards,
René-Luc
More information about the QGIS-Developer
mailing list