title: Delete dynamically create buttons in PyQt5
body: <p>I have created a button who creates buttons in a vertical layout, called "elementos". In each row, there is a label and a X button who should delete the row. There is a list with the text of the label called "puntos" MRE:</p>
  
  <pre class="lang-py prettyprint-override"><code>from PyQt5 import QtCore, QtWidgets
  from PyQt5.QtWidgets import QOpenGLWidget
  import sys
  from sys import argv, exit
  
  
  class Renderizador(QOpenGLWidget):
      def __init__(self, parent=None):
          super().__init__(parent)
          self.puntos = []
          self.num_elementos = 0
  
      def borrar_punto(self):
          self.puntos.pop()
          ui.elementos.removeWidget(self.name)
          ui.elementos.removeWidget(self.borrar)
          self.name.deleteLater()
          self.borrar.deleteLater()
          self.num_elementos -= 1
  
      def crear_punto(self):
          do = ui.valor_do.value()
          cota = ui.valor_cota.value()
          alejamiento = ui.valor_alej.value()
          self.puntos.append((ui.nombre.toPlainText(), do, cota, alejamiento))
          self.name = QtWidgets.QLabel()
          self.name.setText(ui.nombre.toPlainText() + "({}, {}, {})".format(do, cota, alejamiento))
          self.borrar = QtWidgets.QPushButton()
          self.borrar.setText("X")
          self.borrar.clicked.connect(lambda: self.borrar_punto())
  
          ui.elementos.addWidget(self.name, self.num_elementos, 0, 1, 1)
          ui.elementos.addWidget(self.borrar, self.num_elementos, 1, 1, 1)
          self.num_elementos += 1
          self.update()
  
  
  class UiVentana:
      def __init__(self):
          ventana.resize(1500, 1000)
          ventana.setLayoutDirection(QtCore.Qt.LeftToRight)
          ventana.setFixedSize(ventana.size())
  
          self.widget_central = QtWidgets.QWidget(ventana)
          self.gridLayoutWidget = QtWidgets.QWidget(self.widget_central)
          self.gridLayoutWidget.setGeometry(QtCore.QRect(1000, 60, 280, 50))
          self.Vistas = QtWidgets.QGridLayout(self.gridLayoutWidget)
  
          self.Visor = Renderizador(self.widget_central)
          self.Visor.setGeometry(QtCore.QRect(0, 0, 1000, 1000))
  
          self.gridLayoutWidget_2 = QtWidgets.QWidget(self.widget_central)
          self.gridLayoutWidget_2.setGeometry(QtCore.QRect(1004, 105, 300, 400))
          self.Punto = QtWidgets.QGridLayout(self.gridLayoutWidget_2)
          self.Punto.setContentsMargins(5, 5, 5, 5)
          self.Punto.setVerticalSpacing(4)
          self.texto_nombre = QtWidgets.QLabel(self.gridLayoutWidget_2)
          self.texto_nombre.setText("Nombre:")
          self.Punto.addWidget(self.texto_nombre, 3, 0, 1, 1)
          self.crear_punto = QtWidgets.QPushButton(self.gridLayoutWidget_2)
          self.crear_punto.setText("Crear")
          self.crear_punto.clicked.connect(self.Visor.crear_punto)
  
          self.Punto.addWidget(self.crear_punto, 3, 2, 1, 1)
          self.texto_cota = QtWidgets.QLabel(self.gridLayoutWidget_2)
  
          self.nombre = QtWidgets.QTextEdit(self.gridLayoutWidget_2)
          self.nombre.setMaximumSize(QtCore.QSize(100, 24))
          self.Punto.addWidget(self.nombre, 3, 1, 1, 1)
  
          self.scroll = QtWidgets.QScrollArea()
          self.scroll.setWidgetResizable(True)
          self.scroll_widget = QtWidgets.QWidget()
          self.scroll_widget.resize(200, 300)
          self.elementos_widget = QtWidgets.QWidget()
          self.vbox = QtWidgets.QVBoxLayout(self.scroll_widget)
          self.vbox.setContentsMargins(0, 0, 0, 0)
          self.vbox.addWidget(self.elementos_widget)
          self.vbox.addStretch()
          self.elementos = QtWidgets.QGridLayout()
          self.elementos_widget.setLayout(self.elementos)
          self.scroll.setWidget(self.scroll_widget)
          self.scroll_widget.setLayout(self.elementos)
          self.scroll.setWidget(self.scroll_widget)
          self.Punto.addWidget(self.scroll, 4, 0, 1, 3)
  
          self.valor_do = QtWidgets.QSpinBox(self.gridLayoutWidget_2)
          self.Punto.addWidget(self.valor_do, 2, 0, 1, 1)
          self.valor_alej = QtWidgets.QSpinBox(self.gridLayoutWidget_2)
          self.Punto.addWidget(self.valor_alej, 2, 1, 1, 1)
          self.valor_cota = QtWidgets.QSpinBox(self.gridLayoutWidget_2)
          self.Punto.addWidget(self.valor_cota, 2, 2, 1, 1)
  
          ventana.setCentralWidget(self.widget_central)
          ventana.show()
  
  
  def except_hook(cls, exception, traceback):
      sys.__excepthook__(cls, exception, traceback)
  
  
  if __name__ == "__main__":
      app = QtWidgets.QApplication(argv)
      ventana = QtWidgets.QMainWindow()
      ui = UiVentana()
      sys.excepthook = except_hook
      exit(app.exec_())
  </code></pre>
  
  <p>The pop statement should delete from the list the corresponding info about the label. I get an out of index range error, but i get a "RuntimeError: wrapped C/C++ object of type QLabel has been deleted" error if I pop the last statement.
  Full code: <a href="https://github.com/Jaime02/Proyecto-de-investigacion-2019-Dibujo-tecnico/blob/experimental/error" rel="nofollow noreferrer">https://github.com/Jaime02/Proyecto-de-investigacion-2019-Dibujo-tecnico/blob/experimental/error</a> (Lines 120-140)</p>
  
  <p>Edit: The delete button only works once if two or more rows are created</p>