1

I'm using QGIS 3.3 C++ API (python dev should be able to answer too as both C++ and Python API share the same elements names)

I'm trying to display a label on each point of the layer with this expression :

"'L: ' || \"Ref_track\" || ', PK: ' || \"PK\""

This expression works in QGIS 3.3 as

'L: ' || "Ref_track" || ', PK: ' || "PK"

I just adapted it for C++ string writting

here is how i'm doing it :

QgsPalLayerSettings mySettings;
QgsExpression myexp("'L: ' || \"Ref_track\" || ', PK: ' || \"PK\"");
mySettings.fieldName = myexp;

QgsTextFormat txtf;
txtf.setSizeUnit(QgsUnitTypes::RenderPixels);
txtf.setSize(20);
txtf.setColor("#ffffff");
mySettings.setFormat(txtf);


QgsVectorLayerSimpleLabeling* simpleL= new QgsVectorLayerSimpleLabeling(mySettings);

myPointsVectorLayer->setLabeling(simpleL);
myPointsVectorLayer->setLabelsEnabled(true);
myPointsVectorLayer->setCustomProperty("labeling/isExpression", true);

// commit changes
myPointsVectorLayer->commitChanges();

myPointsVectorLayer->updateExtents();
myPointsVectorLayer->triggerRepaint();

When i'm replacing my expression by "Ref_track" it works, but by "\"Ref_track\"" it doesn't ... WHY ?

  • How does it not work? Do you receive an error or are the labels not showing? – Joseph Aug 31 '18 at 13:28
  • no labels showing up, and "isExpression" stay false – NanBlanc Aug 31 '18 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.