title: In a QTableWidget, how to determine if an empty cell is editable?
body: <p>I'm working on a QAction to paste structured text from the clipboard into a QTableWidget. This is my current code:</p>
  
  <pre><code>class PasteCellsAction(qt.QAction):
      def __init__(self, table):
          if not isinstance(table, qt.QTableWidget):
              raise ValueError('CopySelectedCellsAction must be initialised ' +
                               'with a QTableWidget.')
          super(PasteCellsAction, self).__init__(table)
          self.table = table
          self.setText("Paste")
          self.setShortcut(qt.QKeySequence('Ctrl+V'))
          self.triggered.connect(self.pasteCellFromClipboard)
  
      def pasteCellFromClipboard(self):
          """Paste text from cipboard into the table.
  
          If the text contains tabulations and
          newlines, they are interpreted as column and row separators.
          In such a case, the text is split into multiple texts to be paste
          into multiple cells.
  
          :return: *True* in case of success, *False* if pasting data failed.
          """
          selected_idx = self.table.selectedIndexes()
          if len(selected_idx) != 1:
              msgBox = qt.QMessageBox(parent=self.table)
              msgBox.setText("A single cell must be selected to paste data")
              msgBox.exec_()
              return False
  
          selected_row = selected_idx[0].row()
          selected_col = selected_idx[0].column()
  
          qapp = qt.QApplication.instance()
          clipboard_text = qapp.clipboard().text()
          table_data = _parseTextAsTable(clipboard_text)
  
          protected_cells = 0
          out_of_range_cells = 0
  
          # paste table data into cells, using selected cell as origin
          for row in range(len(table_data)):
              for col in range(len(table_data[row])):
                  if selected_row + row &gt;= self.table.rowCount() or\
                     selected_col + col &gt;= self.table.columnCount():
                      out_of_range_cells += 1
                      continue
                  item = self.table.item(selected_row + row,
                                         selected_col + col)
                  # ignore empty strings
                  if table_data[row][col] != "":
                      if not item.flags() &amp; qt.Qt.ItemIsEditable:
                          protected_cells += 1
                          continue
                      item.setText(table_data[row][col])
  
          if protected_cells or out_of_range_cells:
              msgBox = qt.QMessageBox(parent=self.table)
              msg = "Some data could not be inserted, "
              msg += "due to out-of-range or write-protected cells."
              msgBox.setText(msg)
              msgBox.exec_()
              return False
          return True
  </code></pre>
  
  <p>I want to test if a cell is editable before pasting data in it, and for this I get the item using <code>QTableWidget.item(row, col)</code> and then I checks the flags of the item.</p>
  
  <p>My problem is that the <code>.item</code> method returns <code>None</code> for empty cells, so I can't check the flags of empty cells. My code currently only works when there is no empty cell in the paste area. </p>
  
  <p>The error is in lines 46 (<code>None</code> returned) and 50 (<code>AttributeError: 'NoneType' object has no attribute 'flags'</code>):</p>
  
  <pre><code>            item = self.table.item(selected_row + row,
                                     selected_col + col)
              # ignore empty strings
              if table_data[row][col] != "":
                  if not item.flags() &amp; qt.Qt.ItemIsEditable:
                      ...
  </code></pre>
  
  <p>Is there another way of finding out if the cell is editable, other than checking flags of the item?</p>