<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body><div dir="auto">Hi Stephen,<br>You seem to have fallen in the annotation layer "trap" [0]. There is no layer behind and polygon deletion is mentioned in the docs I pointed to. Basically, select it with the "modify annotations" tool on the same toolbar, and press Del.<br><br>To create regular polygon feature, you have to select the layer, turn it into edit mode and use digitizing tools. Read [1].<br><br>Hope that helps.<br>Harrissou<br><br>[0] <a href="https://docs.qgis.org/3.28/en/docs/user_manual/map_views/map_view.html#interaction">https://docs.qgis.org/3.28/en/docs/user_manual/map_views/map_view.html#interaction</a><br>[1] <a href="https://docs.qgis.org/3.28/en/docs/user_manual/working_with_vector/editing_geometry_attributes.html#digitizing-an-existing-layer">https://docs.qgis.org/3.28/en/docs/user_manual/working_with_vector/editing_geometry_attributes.html#digitizing-an-existing-layer</a></div><br><br><div class="gmail_quote"><div dir="auto">Le 11 juin 2023 01:22:43 GMT+02:00, Stephen Sacks via QGIS-User <qgis-user@lists.osgeo.org> a écrit :</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

    <font size="4">My intention was to create a new vector layer
      consisting of several polygons.  I used the CreatePolygon tool to
      mark the four vertices of a rectangle.  I must have done something
      wrong because I've ended up with a polygon that seems to belong to
      no layer.   In desperation I ran the following python code, hoping
      to delete the mysterious polygon, but it's still there.  Are some
      layers not in the legend?  How do I  get rid of the   polygon?   <br>
      ========================<br>
      from qgis.core import QgsProject<br>
      from qgis.utils import iface<br>
      <br>
      project = QgsProject.instance()<br>
      for lyr in project.mapLayers().values():         <br>
          lyrName = lyr.name()<br>
          print (lyrName)<br>
          QgsProject.instance().removeMapLayers([lyr.id()]) <br>
      <br>
          <br>
      <br>
    </font>
  </blockquote></div></body>
</html>