I am trying to change the default symbol for the point/line/ polygon vector layer using QGIS3 C++ APIs.
I was able to render a vector layer with default symbols on QgsMapCanvas
. When I try to change the default symbol of the point vector layer, somehow it is not changing. When I am trying to change color, it does not change color as expected, but the symbol color changes in a different color.
Here is the piece of code.
layer->startEditing();
qDebug()<< "is editable " << layer->isEditable(); // returns true
QgsFeatureRenderer * layerRenderer= layer->renderer();
QgsSingleSymbolRenderer *mSingleRenderer = QgsSingleSymbolRenderer::convertFromRenderer(layerRenderer);
QgsMarkerSymbol* symbol = new QgsMarkerSymbol();
QgsStringMap mp;
mp[QString("name")]= QString("square");
mp[QString("color")]=QString("yellow");
symbol->createSimple(mp);
symbol->setColor(QColor(255,255,255));
mSingleRenderer->setSymbol(symbol);
layer->triggerRepaint();
mLayerTreeView->refreshLayerSymbology(layer->id());
layer->commitChanges();
variable-name layer defines QgsVectorLayer
.