2

I have several tools working with QGIS rubberband before activating my new map tool i want to make sure there is nothing on rubberband previously up to QGIS 3.2 I was able to clean the rubberband via the following code

rbs = [ i for i in canvas.scene().items() if issubclass(type(i), qgis._gui.QgsRubberBand) ]
if len(rbs)>0:
    for rb in rbs:
        if rb in canvas.scene().items():
            canvas.scene().removeItem(rb)

This code no longer works(as QGIS adds some default rubberband and when I try this QGIS crashes now the question is how to have similar functionality (cleaning map canvas from all rubberbands before starting)

1 Answer 1

1

The solution is to change this:

for rb in rbs:
  if rb in canvas.scene().items():
     canvas.scene().removeItem(rb)

to this:

for rb in rbs:
   rb.reset()

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.