Hi
I've been asked to fix a program that uses a QTableView with a few custom delegates to auto-complete data based on row/column. The thing is, it's using PopupCompletion and the value obtained is always the 'first' one.

If I have this example data (QStandard items)
Qt Code:
  1. data|text
  2. 1001|product 1
  3. 1002|product 2
  4. 1003|product 3
  5. ....
To copy to clipboard, switch view to plain text mode 

And I type in "pro", these first 3 items pop up, but upon hitting enter while having selected 1002 or 1003, I get the data as "1001", but the correct text.


This is the SetModelData
Qt Code:
  1. void productNameDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
  2. const QModelIndex &index) const
  3. {
  4.  
  5. QLineEdit *LineEdit = static_cast<QLineEdit*>(editor);
  6. QString value = LineEdit->text();
  7.  
  8. int code=LineEdit->completer()->currentIndex().data(Qt::UserRole).toInt(); //FIXME: Always returns the first element of the (filtered) list, regardless of selection)
  9.  
  10. if (index.column()==2 && index.row()>=6 && index.row() <= 25)
  11. m->addProducto(code, index.row());
  12. model->setData(index, value, Qt::EditRole);
  13.  
  14. }
To copy to clipboard, switch view to plain text mode 

I'm obviously new to Qt, could you help me out?