I'm trying to create some custom labels for point features in a QGIS point vector layer, and I want to write a python plugin to do it. We need our labels to be presented with color tinted rectangles behind them (or else!). The labels are long strings, and are created using labeling engine expressions and conditionals.

I thought the easiest way would be to let the user set up labels for the active layer the way they want, and then let my plugin can grab the label text from the features in the layer and use the text strings to create boxes. My problem is I can't find a way to access those text strings in the QGIS API. How are label strings generated by the labeling engine stored in QGIS and how can I get to them?

  • 1
    By labels do you mean the labels for the individual point features?
    – R.K.
    Dec 22, 2012 at 8:38
  • Yes. And I want it done at the layer level, not at the print composer level. I tried automatically generating text callout boxes because I didn't realize they were print composer features, and that was really ugly. Dec 27, 2012 at 9:44
  • 1
    Have you thought about a strong buffer colour behind the text? I did that on one job. On another I just told the client it was not an option.... It seems a common request....
    – Willy
    Dec 28, 2012 at 23:58
  • 1
    The strong color buffer is my current solution. However, the client had the boxes (using a script) in their ArcGIS implementation, and they want to see the same thing in QGIS. (We're trying to change systems.) My current answer is that this is not an option, but that is never a fun answer, and I would really like to pull something out of my pocket. Plus, boxes around labels should be something we can do. It just makes sense. Dec 30, 2012 at 12:58
  • I think the answer to this is going to be that once the labels are generated by the labeling engine and rendered to the map canvas, they are saved as svg vectors, and not as strings and are thus irretrievable. I saw this on a blog but I have not yet been able to (had the time to) confirm it, so that is not an official answer. (Also, I have learned that shield labels are being worked on as an add for the much anticipated 2.0) Feb 5, 2013 at 20:14

1 Answer 1


In QGIS 2.0, you can create background rectangles, ovals or custom SVG shapes without the need for a plugin. Just go to Layer Properties | Label | Background section.

enter image description here

If you want to code something. This might be a starting point: http://doc.qgis.org/api/qgspallabeling_8cpp_source.html#l04333

  • Lovely! 2.0 is going to be five kinds of cool. We await it with bated breath. Jun 30, 2013 at 15:55

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.