[Qgis-developer] how to use QgsPalLayerSettings class

Yang xmayyang at gmail.com
Wed Feb 12 18:56:03 PST 2014


I'm a newer of qgis

I write a C++ application.
I want to set a layer's label when it smaller than 1.00mm will be not 
visible.

My code is as follows:
void LayerMgr::showLabels(QgsVectorLayer *layer, bool opt)
{
     int index = 0;
     QString attrName = "name";
     QgsPalLayerSettings  labelSetting;
     QgsLabel *layerLabel = layer->label();
     QgsFields field = layer->dataProvider()->fields();

     if (false == opt)
     {
         layer->enableLabels(false);
         return;
     }

     for (index = 0; index < field.size(); index++)
     {
         if (QString(field[index].name()) == attrName)
         {
             break;
         }
     }

     labelSetting.enabled = true;
     labelSetting.fieldName = QString(field[index].name());
     labelSetting.textColor = Qt::black;
     labelSetting.minFeatureSize = 10.0;
     labelSetting.writeToLayer(layer);
     mpMapCanvas->refresh();
}

But it was not usful.Who can help me.
Thank you very much.


More information about the Qgis-developer mailing list