I'm working on a Python plugin for QGIS that applies a customised colorRampItemList to a single band raster. The result displays correctly on the map and in the Layers Panel but incorrectly in the Symbology tab of Layer Properties. I can load the desired color ramp into that tab using setSourceColorRamp but the values and labels are different, and reflect what you get when clicking on Classify in Continuous mode. Is there any way of preventing the customised values/labels from being overridden? The fact that they can be manually edited and retained in Layer Properties implies that there should be.

The disconnect can be replicated in the Python Console by adapting lines 195-212 of test_qgsrasterlayer.py from the QGIS code on GitHub, e.g.:

myRasterLayer = iface.activeLayer()
myRasterShader = QgsRasterShader()
myColorRampShader = QgsColorRampShader()
myItems = []
myItem = QgsColorRampShader.ColorRampItem(10, QColor('#ffff00'), 'foo')
myItem = QgsColorRampShader.ColorRampItem(100, QColor('#ff00ff'), 'bar')
myItem = QgsColorRampShader.ColorRampItem(1000, QColor('#00ff00'), 'kazam')
myPseudoRenderer = QgsSingleBandPseudoColorRenderer(myRasterLayer.dataProvider(), 1, myRasterShader)

Currently working in QGIS 3.6.0 but have had this problem since migrating the plugin from 2.18 to 3.

  • I am having the same issue but with version 3.4.4
    – GreyHippo
    Apr 1, 2019 at 13:28

1 Answer 1


The problem doesn't occur with later versions of QGIS. Not sure exactly when the bug was fixed, but I've just been using my original plugin with QGIS 3.14.0 and values/labels are consistent between the Layers Panel and Layer Properties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.