title: Make QTableView editable when model is pandas dataframe
body: <p>In my gui file I create a QTableView as follows (this is the part that is automatically generated by Qt Designer):</p>
  
  <pre><code>self.pnl_results = QtGui.QTableView(self.tab_3)
  font = QtGui.QFont()
  font.setPointSize(7)
  self.pnl_results.setFont(font)
  self.pnl_results.setFrameShape(QtGui.QFrame.StyledPanel)
  self.pnl_results.setFrameShadow(QtGui.QFrame.Sunken)
  self.pnl_results.setEditTriggers(QtGui.QAbstractItemView.AllEditTriggers)
  self.pnl_results.setShowGrid(True)
  self.pnl_results.setSortingEnabled(True)
  self.pnl_results.setCornerButtonEnabled(True)
  self.pnl_results.setObjectName("pnl_results")
  </code></pre>
  
  <p>I then define a model that enables me to link the pandas dataframe to the QTableView:</p>
  
  <pre><code>class PandasModel(QtCore.QAbstractTableModel):
      """
      Class to populate a table view with a pandas dataframe
      """
  
      def __init__(self, data, parent=None):
          QtCore.QAbstractTableModel.__init__(self, parent)
          self._data = data
  
      def rowCount(self, parent=None):
          return len(self._data.values)
  
      def columnCount(self, parent=None):
          return self._data.columns.size
  
      def data(self, index, role=QtCore.Qt.DisplayRole):
          if index.isValid():
              if role == QtCore.Qt.DisplayRole:
                  return str(self._data.values[index.row()][index.column()])
          return None
  
      def headerData(self, col, orientation, role):
          if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
              return self._data.columns[col]
          return None
  
      def setData(self, index, value, role):
          if not index.isValid():
              return False
          if role != QtCore.Qt.EditRole:
              return False
          row = index.row()
          if row &lt; 0 or row &gt;= len(self._data.values):
              return False
          column = index.column()
          if column &lt; 0 or column &gt;= self._data.columns.size:
              return False
          self._data.values[row][column] = value
          self.dataChanged.emit(index, index)
          return True
  
      def flags(self, index):
          flags = super(self.__class__,self).flags(index)
          flags |= QtCore.Qt.ItemIsEditable
          flags |= QtCore.Qt.ItemIsSelectable
          flags |= QtCore.Qt.ItemIsEnabled
          flags |= QtCore.Qt.ItemIsDragEnabled
          flags |= QtCore.Qt.ItemIsDropEnabled
          return flags
  </code></pre>
  
  <p>and finally a add my pandas dataframe (df) to the model:</p>
  
  <pre><code>model = PandasModel(df)
  self.ui.pnl_results.setModel(model)
  </code></pre>
  
  <p>This correctly displays my pandas dataframe in the QTableView. However, for some reason when I edit the fileds the return to their original values (and also once I edit the field it is starting as empty). How can I make it editable and then write the reults back to the pandas dataframe?</p>