I tried to create a QgsRubberBand object with holes, but failed:

rb = QgsRubberBand(iface.mapCanvas(),True)
geom = QgsGeometry.fromWkt("POLYGON((0 0,4 0,4 3,0 3,0 0),(1 1,3 1,3 2,1 2,1 1))")

Looks like QgsRubberBand doesn't recognize holes at all. Is it a bug, or am I doing something wrong?

  • in QgsRubberBand constructor the II parameters is the geometry type of the rubber band... polygon has value 2 as specified in: qgis.org/api/… Jan 25, 2015 at 21:31
  • Even with the correct geometry type the rubber band doesn't appear to respect geometries with holes. Jul 31, 2015 at 16:13

1 Answer 1


The QgsRubberBand does not support holes. The rubberband it is the kind of thing that is used to represent an ongoing action with the mouse. You would use it to draw the shell of a polygon or cut a hole from an existing shell.

If you need support for holes, you need to use QgsHighlight instead.

  • I just looked up the QgsHighlight but as far as I can tell it needs a (source?) layer to work. The highlight part I need is just to be able to send it a geometry which like in the original question doesn't come from a layer.
    – Chau
    Oct 21, 2016 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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