In my maps I have a symbol, his type is polygon, I want to change the line style of the border, actually is solid , I had to put it in dash

Is there a simple way to change it ? i think to the QgsLineSymbolV2 ?

  • what program are you using. If its Arc you just go into symbology and then choose outline you prefer
    – ed.hank
    Commented Jul 30, 2015 at 14:52
  • no it isn't Arc, it is an application for an industrial project based on QGIS api c++ 2.8.2 and written in c++/QT 4.8.5
    – ainardi
    Commented Jul 30, 2015 at 14:59

2 Answers 2


Refer this post in the SE ..it is for python.Same method can be used for C++


Here is the code in C++ based on the post here : How to set Marker Line symbol for QgsVectorLayer by using Python?

thanks to Durga for the link in his answer.

So here is the code in c++ to change the style of the border of a polygon, in this exemple the color is white and the penstyle is dashed.

QgsSymbolLayerV2Registry * MyRegistry = QgsSymbolLayerV2Registry::instance();
QgsSymbolLayerV2AbstractMetadata * MyLineMeta;

MyLineMeta = MyRegistry->symbolLayerMetadata("SimpleLine");

//create lineMap Properties
QgsStringMap MyLineMap;
QStringList MyLineMapProperties;
MyLineMapProperties <<"width" << "color" << "offset" << "penstyle" << "use_custom_dash" << "joinstyle" << "capstyle";
QStringList MyLineMapValues;
MyLineMapValues << "0.25" << "255,255,255" << "0" << "dash" << "0" << "bevel" << "square";
for (int i =0; i < MyLineMapProperties.size(); i++){

QgsSymbolLayerV2 * MyLineLayer = MyLineMeta->createSymbolLayer(MyLineMap);


Now you can change the color or the pen-style, you can also add some properties if you need that, the properties list can be found in the book The PyQGis Programmer's Guide page 92 to 97

  • 1
    Always great to see people sharing their final solutions! +1
    – Joseph
    Commented Jul 31, 2015 at 10:12

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.