title: Using dynamically added widgets in PyQt/Pyside
body: <p>I have modified the answer given <a href="https://stackoverflow.com/questions/8651742/dynamically-adding-and-removing-widgets-in-pyqt">here</a> as written below. The code is basically creating pushbuttons with a counter as pushButton_0, pushButton_1..
  Here, I know that when I press to <code>self.addButton</code> I am creating widgets named like <code>self.pushButton_0, self.pushButton_1</code> etc. So, my question is, how I'm supposed to use this pushbuttons? Because when I'm trying to do something like <code>self.pushButton_0.clicked.connect(self.x)</code>, it' s telling me that "there is  no attribute named 'pushButton_0'".</p>
  
  <p>Thanks! </p>
  
  <pre><code>from PyQt4 import QtGui, QtCore
  import sys
  
  class Main(QtGui.QMainWindow):
      def __init__(self, parent = None):
          super(Main, self).__init__()
          self.GUI()
  
  
      def GUI(self):
  
          self.count = 0
  
          # main button
          self.addButton = QtGui.QPushButton('button to add other widgets')
          self.addButton.clicked.connect(self.addWidget)
  
          # scroll area widget contents - layout
          self.scrollLayout = QtGui.QFormLayout()
  
          # scroll area widget contents
          self.scrollWidget = QtGui.QWidget()
          self.scrollWidget.setLayout(self.scrollLayout)
  
          # scroll area
          self.scrollArea = QtGui.QScrollArea()
          self.scrollArea.setWidgetResizable(True)
          self.scrollArea.setWidget(self.scrollWidget)
  
          # main layout
          self.mainLayout = QtGui.QVBoxLayout()
  
          # add all main to the main vLayout
          self.mainLayout.addWidget(self.addButton)
          self.mainLayout.addWidget(self.scrollArea)
  
          # central widget
          self.centralWidget = QtGui.QWidget()
          self.centralWidget.setLayout(self.mainLayout)
  
          # set central widget
          self.setCentralWidget(self.centralWidget)
  
      def addWidget(self):
          self.scrollLayout.addRow(Test(self))
          self.count = self.count + 1
          print(self.count)
  
  
  class Test(QtGui.QWidget):
  
      def __init__( self, main):
          super(Test, self).__init__()
          self.Main = main
          self.setup()
  
  
      def setup(self):
  
          print(self.Main.count)
  
          name = "pushButton_"+str(self.Main.count)
          print(name)
  
          self.name = QtGui.QPushButton('I am in Test widget '+str(self.Main.count))
  
  
          layout = QtGui.QHBoxLayout()
          layout.addWidget(self.name)
          self.setLayout(layout)
  
  
  
  app = QtGui.QApplication(sys.argv)
  myWidget = Main()
  myWidget.show()
  app.exec_()
  </code></pre>