I would like to add an on-map drawing function in my stand alone app, so I used QgsRubberBand to make it. I made a tool that emits points and then draw the QgsRubberBand. The problem is I don't find any solution to style it (applying a qml file would be perfect). Here is the code I use to draw my QgsRubberBand:

    def update_largage_eau_canadaire(self, model):
        points = model.largage_eau_canadaire
        #points is an array of QgsPoint
        if len(points) > - 1:
            if self.largage_c_rubber_ is None:
                self.largage_c_rubber_ = QgsRubberBand(self.canvas_, False)

            self.largage_c_rubber_.setToGeometry(QgsGeometry. fromPolyline(points), None)
            self.largage_c_rubber_.setColor(QColor(255, 0, 0, 255))

Here is the result:

Screenshot of my drawn rubberband

And I would like do draw a styled rubberband that would look like this: Example of the result I expect


I think a style like this is impossible for QgsRubberBands. You may set the line style with QgsRubberBand.setLineStyle(p) where p is a value from Qt.PenStyle enumerator, which provides a variety of basic line patterns, but unfortunately no ones as complex as yours.




  • 4
    This is correct - it's not possible to use custom line styles with the rubber band. You may be better off creating a temporary memory layer with a feature matching your rubber band geometry, and then you can style it anyway you want. – ndawson Jan 23 at 19:38
  • Do you have any idea of the way I could match my rubber band to a layer? – Skaldr Jan 30 at 10:36
  • not sure, but check out wether Settings | Snapping Options... does affect your QgsMapToolEmitPoint – Jochen Schwarze Jan 30 at 11:53
  • but I totally agree with @ndawson that memory layers are a far better approach for you than rubber bands. No coding needed, can be made persistent, better styling options, ... – Jochen Schwarze Jan 30 at 11:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.