Hi all, I hope you can help me with this problem.

I have a QTableView in which the first row contains comboboxes (>100). The comboboxes influence the rest of the contents of the QTableView.
I've noticed that the setModelData() method does get called (and the table gets properly updated), but not immediately after selecting a new item from the combobox, but you need to click somewhere else (lose focus) before it gets called. This is quite inconvenient, and I'd like to know how to skip that click.

My comboboxes are made by calling setItemDelegateForRow for the first row of the table. The implementation of createEditor, setEditorData and setModelData is standard. My comboboxdelegate is derived from QStyledItemDelegate. Here is my code from ComboboxDelegate.cpp:

Qt Code:
  1. MainComboBoxDelegate::MainComboBoxDelegate(QObject *parent, MainTableListModel *model) : QStyledItemDelegate(parent)
  2. {
  3. m_model = model;
  4. }
  5.  
  6. QWidget *MainComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & option , const QModelIndex & index) const
  7. {
  8. if(index.row() == 0 && index.column() != 0)
  9. {
  10. QComboBox* editor = new QComboBox(parent);
  11.  
  12. editor->setModel(m_model);
  13. editor->setEditable(false);
  14. return editor;
  15. }
  16. else
  17. return QStyledItemDelegate::createEditor(parent, option, index);
  18. }
  19.  
  20. void MainComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  21. {
  22. if(index.row() == 0)
  23. {
  24. QString temp = index.model()->data(index, Qt::EditRole).toString();
  25. QComboBox *comboBox = static_cast<QComboBox*>(editor);
  26. comboBox->setCurrentIndex(comboBox->findText(temp));
  27. }
  28. }
  29.  
  30. void MainComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
  31. {
  32. if(index.row() == 0)
  33. {
  34. QComboBox *comboBox = static_cast<QComboBox*>(editor);
  35. QString value = comboBox->currentText();
  36. model->setData(index, value, Qt::EditRole);
  37. }
  38. }
  39.  
  40. void MainComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
  41. {
  42. editor->setGeometry(option.rect);
  43. }
To copy to clipboard, switch view to plain text mode 

And this is how I create them in my view class:

Qt Code:
  1. ui->Main_Table_View->setItemDelegateForRow(0, new MainComboBoxDelegate(ui->Main_Table_View, Maintablelistmodel));
  2. for(int i = 1; i < Maintablemodel->columnCount(); ++i)
  3. ui->Main_Table_View->openPersistentEditor(Maintablemodel->index(0, i));
To copy to clipboard, switch view to plain text mode 

The Maintablelistmodel is a QSortFilterProxyModel which contains only one column.
As the comboboxes get created this way, it's hard to pick up signals from them manually, but it may be an option.
Is there something I'm doing wrong, or is it some kind of limitation? Am I missing something?

Any help is highly appreciated.