Example #1
0
   def createEditor(self, parent, styleOption, index):
      if index.column() == 1:
         editor = QDateTimeEdit(parent)
         editor.setDisplayFormat(self.parent().currentDateFormat)
         editor.setCalendarPopup(True)
         return editor

      editor = QLineEdit(parent)
      # create a completer with the strings in the column as model
      allStrings = []
      for i in range(1, index.model().rowCount()):
         strItem = index.model().data(index.sibling(i, index.column()), Qt.EditRole)
         if strItem not in allStrings:
            allStrings.append(strItem)
      aS = [str(x.toString()) for x in allStrings]
      autoComplete = QCompleter(QStringList(",".join(aS)))
      editor.setCompleter(autoComplete)
      editor.editingFinished.connect(self.commitAndCloseEditor)
      return editor